zoukankan      html  css  js  c++  java
  • Boost.Date_Time 使用

    Date Programming

    View Code
    #include <boost/date_time/gregorian/gregorian.hpp>
    
    using namespace boost::gregorian;;
    
    int main()
    {
        date d1(2002,Feb,1),d3, d4(2002,Feb,1);
        date weekstart(2002,Feb,1);
        date weekend  = weekstart + weeks(1);
        date d2 = d1 + days(5);
        date today = day_clock::local_day();
        if (d2 >= today) {} //date comparison operators 
    
        date_period thisWeek(d1,d2);
        if (thisWeek.contains(today)) {}//do something 
    
        //iterate and print the week
        day_iterator itr(weekstart);
        while (itr <= weekend) {
         std::cout << (*itr) << std::endl;
         ++itr;
        }  
        //input streaming 
        std::stringstream ss("2004-Jan-1");
        ss >> d3;
    
        //date generator functions 
        date d5 = next_weekday(d4, (greg_weekday)Tuesday); //calculate Sunday following d4
    
        //US labor day is first Monday in Sept 
        typedef nth_day_of_the_week_in_month nth_dow;
        nth_dow labor_day(nth_dow::first,Monday, Sep); 
        //calculate a specific date for 2004 from functor 
        date d6 = labor_day.get_date(2004); 
    
    }

    Time Programming

    #include "boost/date_time/posix_time/posix_time.hpp"

    Local Time Programming

    boost时间有些感觉并不好用,过度复杂化了。

  • 相关阅读:
    php--有限继承
    面向对象三大特性(封装/继承/多态)
    定义文本溢出
    设计模式
    js数组sort方法
    鼠标移动事件
    单击事件
    数据类型转换与比较
    html主要笔记
    字符串常用的方法
  • 原文地址:https://www.cnblogs.com/logitechlike/p/2833770.html
Copyright © 2011-2022 走看看