首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

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

2013-04-26 
strftime函数使用%g格式符的问题strftime(year, 10, %g, localtime(&tms.tv_sec))%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年的周”?谢谢!
[解决办法]

     %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


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

热点排行