I've been looking through this sites posts on this issue i have, and none of them solve my problem so far. What happens is that my datetime.now()
method from datetime
module doesnt show time as configured in my pc, so here i did some tests in order to figure out what's happening. a few minutes ago I solved it by specifying the timezone through dateutil
module, but it shouldn't be done in that way.
Note: I'm currently using Ubuntu/Linux OS, and use a virtual environment for my project.
CODE:
from dateutil import tz
from datetime import date, datetime, time
date1 = datetime.now(tz.tzlocal()) # it works not at all
date1_ = datetime.now() # Same thing
date2 = datetime.now(tz.gettz('Cuba')) # it does now
date1_tz_info = date1.timetz()
print(date1, date1_, date2, sep='
')
print(date1_tz_info)
OUTPUT:
- 2021-01-19 22:39:13.960834+00:00
- 2021-01-19 22:39:13.960874
- 2021-01-19 17:39:13.961087-05:00 #The Right Output
- 22:39:13.960834+00:00
Picture from pc
So as far as seen now datetime.now() returns value as if it was utc +00:00.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…