Python’s datetime class has a fromtimestamp method to create a datetime object from a timestamp, but doesn’t provide a totimestamp method for the other way round…
I’m aware that with something like time.mktime(x.timetuple()) you can convert the datetime object to a timestamp, but this looks unnecessary complicated to me, so I’m curious why there is no totimestamp method?
Python’s datetime class has a fromtimestamp method to create a datetime object from a
Share
I do remember a discussion/bug report about this thing while I wondered about this some time back. Long story short: plenty of proposals have been made, but for some reason, none have been accepted.
The point is I think best summed up in this reply:
The end result to this story was that documentation was added on how to do it yourself: