2
You want to print the local time and the correct function for this is the localtime()
, and not the gmtime()
which 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()))
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
Just be careful because in many cases it is right to work with universal time and not local. We even see a lot of questions here from people who are having a hard time getting started on systems wrong and then can’t get any more.
Conceptually there is already a mistake in this +0000
which gives misleading information, and even a +0300
will only be right by coincidence at certain times of the year. But the subject is absurdly extensive to put here.
And how can we know what is wrong? For me it is right. By chance this gives the result you expect?
print(strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()))
– Maniero
Yes, so it was without any anomaly, would you happen to know where could be the error in my code? 'Cause I followed exactly the code of your documentation
– Bruno G
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero