Why Datetime module is showing wrong Date/time? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Why Datetime module is showing wrong Date/time?

I was testing Datetime module for a project and I found that it's showing wrong date and time. I want to know if Datetime module shows time for just specific time/country zone or it changes according to different time zones? Code and my results here: https://code.sololearn.com/cs1dM356M0fY/?ref=app

13th Jan 2021, 6:50 PM
Arctic Fox
Arctic Fox - avatar
3 Answers
+ 6
Arctic Fox this problem can be fixed by passing in a timezone into the datetime.now() method. The timezone is specfied by passing in your timezone into the timezone() function of the `pytz` module. See this code for a better explanation https://code.sololearn.com/c8Bof68SYv3m/?ref=app
13th Jan 2021, 7:08 PM
XXX
XXX - avatar
+ 4
Thanks XXX and Martin Taylor for helping! Didn't knew about 'pytz' module Edit: Thanks @Mirielle
13th Jan 2021, 7:11 PM
Arctic Fox
Arctic Fox - avatar
+ 3
Martin Taylor Is there Any fix possible to change time according to the local time zone?
13th Jan 2021, 7:05 PM
Arctic Fox
Arctic Fox - avatar