strftime函数使用%g格式符的有关问题
strftime函数使用%g格式符的问题
strftime(year, 10, "%g", localtime(&tms.tv_sec));
%g 年份的后两位数字,使用基于周的年
%y 不带世纪的十进制年份(值从0到99)
12月31日是2013年的周,所以2012年12月31日用该函数得到的是31DEC13。
请问为什么“12月31日是2013年的周”?谢谢!
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
简短捷说就是周跨不跨年。
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
------解决方案--------------------
简短捷说就是周跨不跨年。