+ -
当前位置:首页 → 问答吧 → [已解决]帮忙测试 Python 的 strftime 函数

[已解决]帮忙测试 Python 的 strftime 函数

时间:2009-02-10

来源:互联网

代码:
vvoody@slackware:~$ python
Python 2.5.2 (r252:60911, Sep 11 2008, 13:43:31)
[GCC 4.2.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from time import strftime, gmtime, localtime
>>> strftime("%a, %d %b %Y %H:%M:%S", gmtime(1234567890))
'Fri, 13 Feb 2009 23:31:06'

>>> strftime("%a, %d %b %Y %H:%M:%S", localtime(1234567890))
'Sat, 14 Feb 2009 07:31:30' 

>>> strftime("%a, %d %b %Y %H:%M:%S", gmtime(915148821))
'Thu, 31 Dec 1998 23:59:60'
我的是 12.2, 同样平台的朋友帮忙贴一下你们的上面三个运行结果。应该 1234567890 是 23:31:30,我询问了很多人他们也都是正确的。而就我少了 24 秒。问题在于,1998 年那次的闰秒 strftime 加上了,而今年的似乎没有加上,如果加上至今的 24 秒那么秒就是正确结果了。

已解决,用 root 重新运行一下 timeconfig。

作者: vvoody   发布时间: 2009-02-10

代码:
>>> from time import strftime, gmtime, localtime
>>> strftime("%a, %d %b %Y %H:%M:%S", gmtime(1234567890))
'Fri, 13 Feb 2009 23:31:30'
>>> strftime("%a, %d %b %Y %H:%M:%S", localtime(1234567890))
'Sat, 14 Feb 2009 07:31:30'
>>> strftime("%a, %d %b %Y %H:%M:%S", gmtime(915148821))
'Fri, 01 Jan 1999 00:00:21'
no problem, use the slackware current

作者: ginkgo   发布时间: 2009-02-10

晕啊,就我有问题诶。。。

作者: vvoody   发布时间: 2009-02-10

代码:
/usr/local/src/My_projects$ python
Python 2.5.2 (r252:60911, Sep 11 2008, 13:43:31)
[GCC 4.2.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from time import strftime, gmtime, localtime
>>> strftime("%a, %d %b %Y %H:%M:%S", gmtime(1234567890))
'Fri, 13 Feb 2009 23:31:30'
>>> strftime("%a, %d %b %Y %H:%M:%S", localtime(1234567890))
'Sat, 14 Feb 2009 07:31:30'
>>> strftime("%a, %d %b %Y %H:%M:%S", gmtime(915148821))
'Fri, 01 Jan 1999 00:00:21'
>>>
可能会是 gmtime 的原因,因为 strftime 貌似只是格式化输出,不进行转换。

作者: grissiom   发布时间: 2009-02-11

引用:
作者: grissiom
代码:
/usr/local/src/My_projects$ python
Python 2.5.2 (r252:60911, Sep 11 2008, 13:43:31)
[GCC 4.2.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from time import strftime, gmtime, localtime
>>> strftime("%a, %d %b %Y %H:%M:%S", gmtime(1234567890))
'Fri, 13 Feb 2009 23:31:30'
>>> strftime("%a, %d %b %Y %H:%M:%S", localtime(1234567890))
'Sat, 14 Feb 2009 07:31:30'
>>> strftime("%a, %d %b %Y %H:%M:%S", gmtime(915148821))
'Fri, 01 Jan 1999 00:00:21'
>>>
可能会是 gmtime 的原因,因为 strftime 貌似只是格式化输出,不进行转换。
都是一样的包,为啥哦~真是诡异啊。

作者: vvoody   发布时间: 2009-02-11

>>> strftime("%a, %d %b %Y %HMS", gmtime(1234567890))
'Fri, 13 Feb 2009 23:31:30'
>>> strftime("%a, %d %b %Y %HMS", localtime(1234567890))
'Sat, 14 Feb 2009 07:31:30'
>>> strftime("%a, %d %b %Y %HMS", gmtime(915148821))
'Fri, 01 Jan 1999 00:00:21'

作者: sunny_5252   发布时间: 2009-02-11

引用:
作者: vvoody
都是一样的包,为啥哦~真是诡异啊。
是啊…… 如果重新安装一遍呢?……

作者: grissiom   发布时间: 2009-02-11

引用:
作者: grissiom
是啊…… 如果重新安装一遍呢?……
我 timeconfig 了一下就好了。。。

作者: vvoody   发布时间: 2009-02-11

估计是时区选错了

作者: slackcode   发布时间: 2009-02-12

引用:
作者: slackcode
估计是时区选错了
问题在于 localtime 是正确的,而 gmtime 则不对。

作者: vvoody   发布时间: 2009-02-13