在1900年之前使用datetime.strftime()吗? (“require year”= 1900“) [英] Use datetime.strftime() on years before 1900? ("require year >= 1900")
问题描述
我用过:
utctime = datetime.datetime(1601,1,1)+ datetime.timedelta(microseconds = tup [5])
last_visit_time =最后访问时间:+ utctime.strftime('%Y-%m-%d%H:%M:%S')
但是我有1601的时间,所以错误显示:
ValueError:year = 1601是在1900之前; datetime strftime()方法需要年> = 1900
But I have the time of 1601, so the error show:
ValueError: year=1601 is before 1900; the datetime strftime() methods require year >= 1900
我使用python2.7,我该怎么做?非常感谢!
I used python2.7, how can I make it? Thanks a lot!
推荐答案
您可以执行以下操作:
>>> utctime.isoformat()
'1601-01-01T00:00:00.000050'
现在如果你想要具有与上述完全相同的格式:
Now if you want to have exactly the same format as above:
iso = utctime.isoformat()
tokens = iso.strip().split("T")
last_visit_time = "Last visit time: %s %s" % (tokens[0], tokens[1].strip().split(".")[0])
不是似乎有一个修补程序 strftime
来修复此行为此处(未测试)
Not that there seems to be a patch for strftime
to fix this behavior here (not tested)
这篇关于在1900年之前使用datetime.strftime()吗? (“require year”= 1900“)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!