我正在使用Python开发Google应用引擎。
我已经在数据库中存储了一个datetime对象并获取了它并应用了时区,我使用模板保存了它。结果是"2011-03-15 16:54:24.398503+09:00"
,但我想要的是:"2011-03-16 01:54:24"
(时区应用的字符串没有毫秒 - 请注意日期已更改)。
我该怎么做?
答案 0 :(得分:2)
一旦你有了datetime对象,就像使用strftime一样;
from datetime import datetime
datetime.now().strftime('%Y-%m-%d %H:%M:%S')
http://docs.python.org/release/2.6.6/library/datetime.html#strftime-and-strptime-behavior
答案 1 :(得分:0)
鼓励使用strftime,但请确保您的本地时间正确。假设您正在使用django,这应该是您的应用/网站中的设置,或者您可能必须手动执行此操作