不同的时间元组格式 [英] different time tuple format
问题描述
大家好,很抱歉,如果我要重新发布
为什么time.strptime和time.localtime会返回不同DST的元组(元组的9项)?
是否有一些解决问题的设置?
Python 2.2.3(#1,2005年5月31日,11:33:52)
[GCC 2.95.4 20020320 [FreeBSD]]关于freebsd4
输入help,quot; copyright,credit等等。或许可证或更多信息。
hi all, sorry if i''m reposting
why time.strptime and time.localtime returns tuple with different DST (9 item of the tuple)?
is there some of setting to fix the problem?
Python 2.2.3 (#1, May 31 2005, 11:33:52)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
import time
time.strptime(" 2005-06-07 21:00:00" ;,%Y-%m-%d%H:%M:%S)
(2005,6,7,21,0,0,6,1,0)time.localtime()
(2005,6,7,21,2,39,1,158,1)
import time
time.strptime("2005-06-07 21:00:00", "%Y-%m-%d %H:%M:%S") (2005, 6, 7, 21, 0, 0, 6, 1, 0) time.localtime() (2005, 6, 7, 21, 2, 39, 1, 158, 1)
-
祝你好运,
Maksim Kasimov
mailto: ka ** ***@i.com.ua
推荐答案
http://docs.python.org/lib/module-time.html 告诉我们最后一个元素
是您的计算机上的DST标志,适用于localtime()。要使用strptime()获得
,你必须调整%Z格式化程序 - 这是特定于平台的b $ b。
http://docs.python.org/lib/module-time.html tells us the last element
is the DST flag, on your computer that applies for localtime(). To get
this with strptime() you have to tweak the %Z formatter - this is
platform specific.
就像最后一张海报说的那样,使用%Z。在我的Mandriva Linux系统上,我得到
以下结果:
Like the last poster said, use %Z. On my Mandriva Linux system I get the
following results:
time.localtime ()
(2005,6,7,15,7,12,1,158,1)time.strptime(" 2005-06-07 15:07:12 EDT","%Y-% m-%d%H:%M:%S%Z)
time.localtime() (2005, 6, 7, 15, 7, 12, 1, 158, 1) time.strptime("2005-06-07 15:07:12 EDT", "%Y-%m-%d %H:%M:%S %Z")
(2005,6,7,15,7,12,1,158,1)
>
Rick
Maksim Kasimov写道:
(2005, 6, 7, 15, 7, 12, 1, 158, 1)
Rick
Maksim Kasimov wrote:
大家好,很抱歉,如果我重新发布
为什么time.strptime和time.localtime返回具有不同DST的元组(元组的9项)?是否有一些设置来解决问题?
Python 2.2.3(#1,2005年5月31日,11:33:52)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
输入help,copyright,credit等等。或许可证或欲获得更多信息。 >>>导入时间
>>> time.strptime(2005-06-07 21:00:00,%Y-%m-%d%H:%M:%S)(2005,6,7,21,0,0) ,6,1,0)>>> time.localtime()(2005,6,7,21,2,39,1,158,1)>>>
hi all, sorry if i''m reposting
why time.strptime and time.localtime returns tuple with different DST (9
item of the tuple)? is there some of setting to fix the problem?
Python 2.2.3 (#1, May 31 2005, 11:33:52)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information. >>> import time
>>> time.strptime("2005-06-07 21:00:00", "%Y-%m-%d %H:%M:%S") (2005, 6, 7, 21, 0, 0, 6, 1, 0) >>> time.localtime() (2005, 6, 7, 21, 2, 39, 1, 158, 1) >>>
Rick Holbert写道:
Rick Holbert wrote:
就像最后一张海报所说,使用%Z。在我的Mandriva Linux系统上,我得到了以下结果:
Like the last poster said, use %Z. On my Mandriva Linux system I get the
following results:
time.localtime()
(2005 ,6,7,15,7,12,1,158,1)
time.strptime(" 2005-06-07 15:07:12 EDT","%Y-%m-%d %H:%M:%S%Z)(2005,6,7,15,7,12,1,158,1)
time.localtime()
(2005, 6, 7, 15, 7, 12, 1, 158, 1)
time.strptime("2005-06-07 15:07:12 EDT", "%Y-%m-%d %H:%M:%S %Z") (2005, 6, 7, 15, 7, 12, 1, 158, 1)
不起作用完全:ValueError:格式不匹配
我已经检查了time.tzname的价值:
(''EET'',' 'EEST'')
并获得以下(再次):
does not work at all: "ValueError: format mismatch"
i''ve check the value of time.tzname:
(''EET'', ''EEST'')
and get the following (again):
time.strptime(" 2005-06-07 15: 07:12 EET","%Y-%m-%d%H:%M:%S%Z")
time.strptime("2005-06-07 15:07:12 EET", "%Y-%m-%d %H:%M:%S %Z")
(2005 ,6,7,15,7,12,6,1,0)
-
祝你好运,
Maksim Kasimov
mailto: ka ***** @ i。 com.ua
这篇关于不同的时间元组格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!