ISO 格式的日期时间,毫秒到 000
Datetime in ISO format with milliseconds to 000
我的代码 datetime.now(timezone.utc).astimezone(pytz.timezone("Europe/Berlin")).isoformat()
打印以下格式 '2020-03-17T16:54:53.559415+01:00'
但我希望毫秒为 0000 '2020-03-17T16:54:53.000+01:00'
。
我已经尝试使用 replace(miliseconds=0)
但它从打印的字符串中完全删除了毫秒数。
您希望 .replace(microsecond=0)
将毫秒(和微)秒归零。然后指定右边的timespec
为isoformat
,'milliseconds'
:
nowzeroed = datetime.now(timezone.utc).replace(microsecond=0)
nowberlin = nowzeroed.astimezone(pytz.timezone("Europe/Berlin"))
nowformatted = nowberlin.isoformat(timespec='milliseconds')
我的代码 datetime.now(timezone.utc).astimezone(pytz.timezone("Europe/Berlin")).isoformat()
打印以下格式 '2020-03-17T16:54:53.559415+01:00'
但我希望毫秒为 0000 '2020-03-17T16:54:53.000+01:00'
。
我已经尝试使用 replace(miliseconds=0)
但它从打印的字符串中完全删除了毫秒数。
您希望 .replace(microsecond=0)
将毫秒(和微)秒归零。然后指定右边的timespec
为isoformat
,'milliseconds'
:
nowzeroed = datetime.now(timezone.utc).replace(microsecond=0)
nowberlin = nowzeroed.astimezone(pytz.timezone("Europe/Berlin"))
nowformatted = nowberlin.isoformat(timespec='milliseconds')