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