Wednesday, 20 March 2019

python - Are these two formatting date methods really equivalent?

It seems that:




time.strftime("%Y-%m-%d %H:%M:%S")
#2017-01-12 10:46:57

datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")
#2017-01-12 10:46:57


are equivalent. When I read many questions/answers here, or tutorials or documentation, some of them use the former, some the latter.



Are they 100% equivalent? When to prefer the one or the other?




PS: the latter seems to be equivalent to datetime.date.fromtimestamp(time.time()), but is this equivalent to time.strftime(...)?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...