美丽心灵公益论坛

查看: 1871|回复: 0

Boost官方日期库

[复制链接]
累计签到:57 天
连续签到:1 天

981

主题

461

回帖

8037

积分

版主

Rank: 7Rank: 7Rank: 7

积分
8037
发表于 2022-4-26 21:24:30| 字数 722 来自手机 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
using namespace boost::gregorian;
    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, Sunday); //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);
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|免责及版权声明|关于|美丽心灵公益论坛

GMT+8, 2025-11-21 12:50 , Processed in 0.268353 second(s), 26 queries .

Powered by Discuz! X3.4

!copyright!

快速回复 返回顶部 返回列表