0

I have a timestamp created with date(1) as date --rfc-3339=ns. It looks like "2019-12-06 13:02:21.711339765+05:30". What is the canonical way to parse it with strptime() if strptime() does not support nanoseconds?

PS. The tag "c" is because Python uses C runtime strptime(3) function - they have the same API, so your answer may be relevant for both languages

RandomB
  • 3,367
  • 19
  • 30
  • There are some functions for handling these timestamps at https://github.com/chansen/c-timestamp . Actually, it handles timestamps with a `T` separating the date from the time instead of a space, but maybe you can work around that. – Ian Abbott Dec 09 '19 at 13:44
  • hm, so no way to do it with `strptime()`... OK – RandomB Dec 09 '19 at 13:49
  • Oh, it looks like the code in link I posted handles either `T`, `t` or ` ` (space) as a separator, so maybe worth checking out. It appears to have a BSD style license. – Ian Abbott Dec 09 '19 at 13:51
  • `strptime` doesn't handle the fractional seconds, but you could maybe use it to parse some sections of the string. The POSIX standard version of `strptime` has no `%z` to parse the timezone and has nowhere in `struct tm` in which to store the UTC offset. – Ian Abbott Dec 09 '19 at 13:53
  • 1
    I guess the link I posted is no good to you for Python, although I'm sure similar stuff must exist, e.g. https://pypi.org/project/pyRFC3339/ . – Ian Abbott Dec 09 '19 at 14:03

0 Answers0