简体   繁体   English

如何在django 1.6中使用time.strftime

[英]how to work with time.strftime in django 1.6

I am one of the new user in django 1.6 but one thing very bad I have noticed in this version of django is that time.strftime("%H:%M:%S") does not working and giving a wrong time in my view . 我是django 1.6中的新用户之一,但有一点非常糟糕我在这个版本的django中注意到time.strftime(“%H:%M:%S”)无法正常工作并且在我的错误时间查看。 Is there any alternating approach for getting a right time in django view or not ? 在django视图中是否有任何交替的方法来获得正确的时间?

Note : if you type print(time.strftime("%H:%M:%S")) in python 3 you will see a right time but in django 1.6 it is not true 注意:如果在python 3中输入print(time.strftime(“%H:%M:%S”)),你会看到正确的时间,但是在django 1.6中它不是真的

Thank you. 谢谢。

Maybe you're dealing with UTC time. 也许你正在处理UTC时间。 Convert it to local time before call strftime : 在调用strftime之前将其转换为本地时间:

>>> from django.utils import timezone
>>> now = timezone.now()
>>> now.strftime('%H:%M:%S')
'13:23:52'
>>> timezone.localtime(now).strftime('%H:%M:%S')
'22:23:52'

See Time zones | 查看时区| Django documentation . Django文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM