读书人

strftime函数使用%g格式符的有关问题

发布时间: 2013-04-26 16:27:53 作者: rapoo

strftime函数使用%g格式符的问题
strftime(year, 10, "%g", localtime(&tms.tv_sec));
%g 年份的后两位数字,使用基于周的年
%y 不带世纪的十进制年份(值从0到99)
12月31日是2013年的周,所以2012年12月31日用该函数得到的是31DEC13。

请问为什么“12月31日是2013年的周”?谢谢!
[解决办法]

     %g    is replaced by the same year as in ``%G'', but as a decimal number
without century (00-99).

[解决办法]
     %G    is replaced by a year as a decimal number with century.  This year
is the one that contains the greater part of the week (Monday as
the first day of the week).

[解决办法]

另外我的mac显示2013-12-31应该算是2014的周

$ date -j -f '%Y-%m-%d' 2013-12-31 '+%G'
2014


[解决办法]
简短捷说就是周跨不跨年。

读书人网 >C语言

热点推荐