从提升日期对象获取月份

Ric*_*hip 5 c++ boost boost-date-time

我有一个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.
Run Code Online (Sandbox Code Playgroud)

我需要在不将boost对象恢复到tm结构的情况下得到它.这会导致过多的转换和可能的性能损失.

jfl*_*fly 6

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