timetuple() does not use milliseconds, so the ms information contained in the datetime object is lost after calling the method:
>>> d datetime.datetime(2000, 1, 2, 3, 4, 5, 678) >>> d.timetuple() time.struct_time(tm_year=2000, tm_mon=1, tm_mday=2, tm_hour=3, tm_min=4, tm_sec=5, tm_wday=6, tm_yday=2, tm_isdst=-1)
Note that this is not a limitation of this particular method, but rather a time.struct_time type .
Bottom line: if you need to override the timestamp, do not go through the time.struct_time object. You could, for example, pass a timestamp already formatted as a string, rather than a fake time. Of course, depending on your needs, there may be better methods.
source share