Python 3 datetime.fromtimestamp fails by 1 microsecond
问题 I want to save datetimes with microsecond resolution as timestamps. But it seems that Python 3 datetime module lost one microsecond when loading them. To test this let's create a script: test_datetime.py : from random import randint from datetime import datetime now = datetime.now() for n in range(1000): d = datetime(year=now.year, month=now.month, day=now.day, hour=now.hour, minute=now.minute, second=now.second, microsecond=randint(0,999999)) ts = d.timestamp() d2 = datetime.fromtimestamp(ts