Infintyyy
Infintyyy

Reputation: 949

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 . Is there any alternating approach for getting a right time in django view or not ?

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

Thank you.

Upvotes: 3

Views: 5814

Answers (1)

falsetru
falsetru

Reputation: 369074

Maybe you're dealing with UTC time. Convert it to local time before call 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.

Upvotes: 5

Related Questions