【问题标题】:Getting month from boost date object从提升日期对象获取月份
【发布时间】:2014-01-23 12:51:36
【问题描述】:

我有一个 boost::date 对象。当我在对象上调用 month() 接口时,它会返回对象所持有的月份,但以字符串的形式返回。有没有办法获得与月份相关的数字?即

date mySampleDate = date_from_tm(tm_myDate) ;
cout<<mySampleDate.month() ; //Gives the output as May/Jun/Jul etc. I need 5/6/7 etc.

我需要在不将 boost 对象恢复到 tm 结构的情况下得到它。这会导致转化次数过多,并可能影响我的性能。

【问题讨论】:

    标签: c++ boost boost-date-time


    【解决方案1】:

    cout&lt;&lt;mySampleDate.month().as_number(); 正是你想要的!

    【讨论】:

    • 这是如何在 boost 中实现的? .month() 是否返回一些具有 as_number() 方法的类?
    • @BehroozKarjoo 内部boost::date 是一个模板类,它的模板参数之一calendar 定义了转换年月日的策略。 month() 返回calendar::month_type
    猜你喜欢
    • 1970-01-01
    • 2019-01-07
    • 2017-04-05
    • 2019-03-20
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 2018-12-08
    相关资源
    最近更新 更多