I have these dates
2016-02-26 12:12:12
2016-02-friday 12:12:12
(Those two dates refers to the same day)
If I convert the first one in a timestamp and then convert it back in a readable format it works.
But if I try the same on the second one it does not convert back to the right day !
Here's what I did :
sTimestamp = time.mktime(
datetime.datetime.strptime(
"2016-02-26 12:12:12",
"%Y-%m-%d %H:%M:%S")
.timetuple())
print("date from timestamp = " +
datetime.datetime.fromtimestamp(int(sTimestamp))
.strftime('%Y-%m-%d %H:%M:%S'))
sTimestamp = time.mktime(
datetime.datetime.strptime(
"2016-02-friday 12:12:12",
"%Y-%m-%A %H:%M:%S")
.timetuple())
print("date from timestamp = " +
datetime.datetime.fromtimestamp(int(sTimestamp)).
strftime('%Y-%m-%d %H:%M:%S'))
The output of thoses two lines are :
- date from timestamp = 2016-02-26 12:12:12
- date from timestamp = 2016-02-01 12:12:12
As you can see the first one is back to 26 but the second one converts back to 01 for an unknown reason. And by the way, 01 is a monday...
For information I am using python 3.4 and I am on Windows.