You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2020-03-26.21:07:35.837>created_at=<Date2020-03-26.14:14:48.206>labels= ['type-bug', '3.8', '3.9', 'invalid', '3.7', 'library']
title='isoformat function drops microseconds part if its value is 000000'updated_at=<Date2020-03-26.21:11:20.750>user='https://bugs.python.org/AlexanderBolshakov'
Return a string representing the date and time in ISO 8601 format:
YYYY-MM-DDTHH:MM:SS.ffffff, if microsecond is not 0
YYYY-MM-DDTHH:MM:SS, if microsecond is 0
The optional argument timespec specifies the number of additional components of the time to include (the default is 'auto'). It can be one of the following:
'auto': Same as 'seconds' if microsecond is 0, same as 'microseconds' otherwise.
'hours': Include the hour in the two-digit HH format.
'minutes': Include hour and minute in HH:MM format.
'seconds': Include hour, minute, and second in HH:MM:SS format.
'milliseconds': Include full time, but truncate fractional second part to milliseconds. HH:MM:SS.sss format.
'microseconds': Include full time in HH:MM:SS.ffffff format.
./python
Python 3.9.0a4+ (heads/master:6723e933c4, Mar 21 2020, 06:54:01)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime(1, 1, 1).isoformat(timespec='auto')
'0001-01-01T00:00:00'
>>> datetime.datetime(1, 1, 1).isoformat(timespec='microseconds')
'0001-01-01T00:00:00.000000'
isoformat function does not conform to the ISO 8601 and drops microseconds part if its value is 000000.
I'm not sure why you think that this does not conform to ISO 8601 - ISO 8601 is a sprawling beast of a spec and allows some crazy formats. Some examples of perfectly valid ISO 8601 strings:
There are *hundreds* of valid formats encompassed by ISO 8601.
Anyway, that's an aside. The behavior of .isoformat() is pretty clearly documented. These are the first three line of the documentation:
Return a string representing the date and time in ISO 8601 format:
- YYYY-MM-DDTHH:MM:SS.ffffff, if microsecond is not 0
- YYYY-MM-DDTHH:MM:SS, if microsecond is 0
I believe Karthikeyan has adequately explained how to get the behavior you want, so I am going to go ahead and close this as working as intended.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: