Time out with unexpected result

2

I'm running a code that sets the hours in the terminal but when I use the code below it brings me a totally wrong value at the time:

Code:

from time import gmtime, strftime
print(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))

Here is the value it returns:

    
asked by anonymous 20.09.2018 / 22:42

1 answer

1

You want to print the local time and the correct function for this is localtime() , not the gmtime() that gives you the universal call time (no time zone).

from time import localtime, strftime
print(strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()))

See running on ideone . And in Coding Ground . Also put GitHub for future reference .

Just be careful because in many cases the correct thing is to work with universal and not local time. We even see a lot of questions here from people who are having trouble getting started using it wrong on systems and then can not fix it anymore.

Conceptually there is already an error in this +0000 fixed that gives misleading information, and even +0300 will only be certain by coincidence at certain times of the year. But the subject is absurdly extensive to put here.

    
20.09.2018 / 22:53