What is yy-mm-dd'D' format?

Viewed 85

I got some csv file. Inside file, there is timestamp like this

timestamp
2018-08-04D00:00:03.340429000
2018-08-04D00:00:03.911072000
2018-08-04D00:00:04.109119000
2018-08-04D00:00:05.348754000
2018-08-04D00:00:07.569001000
2018-08-04D00:00:08.666946000
2018-08-04D00:00:09.247728000
2018-08-04D00:00:09.247728000
2018-08-04D00:00:09.538240000
2018-08-04D00:00:09.715869000

I couldn't convert it to code because of yy-mm-dd 'D'. I searched google but I can't find about reference the format.. Is there anyone know about the format?

2 Answers

I think this is a weird variation of ISO 8601. It can be parsed with a format string:

datetime.strptime(d[:-3], "%Y-%m-%dD%H:%M:%S.%f")

The beauty of the datetime module is that you can use it to parse almost anything, as long as you know what you are looking for:

import datetime
datetime.datetime.strptime("2018-08-04D00:00:03.340429000", 
                           "%Y-%m-%dD%H:%M:%S.%f000")
#datetime.datetime(2018, 8, 4, 0, 0, 3, 340429)

Note that '%f' parses microseconds and demands that there are only six decimal places after the decimal point. The remaining three zeros in my format string tell strptime that the last three digits of the string (the nanoseconds) are always zeros.

Related