When exporting ISO times to milliseconds, are extra digits rounded?
The timespec argument controls output precision in isoformat. Excluded fractional digits are truncated.
Python example and interpretation
123999 microseconds is printed as .123. Neighboring events can serialize to the same millisecond, so retain finer precision or a sequence number for ordering.
from datetime import datetime
datetime(2026,4,1,0,0,0,123999).isoformat(timespec='milliseconds')Result '2026-04-01T00:00:00.123'
中文
以毫秒导出 ISO 时间时,多余微秒是舍入还是截断?
isoformat 的 timespec 控制输出精度,被省略的小数部分采用截断。
Python 算例与适用条件
123999 微秒显示为 .123。两个相邻事件可能导出同一个毫秒字符串,稳定排序还需要保留原始精度或序号。
from datetime import datetime
datetime(2026,4,1,0,0,0,123999).isoformat(timespec='milliseconds')结果 '2026-04-01T00:00:00.123'