I have multiples strings representing timestamps. A few examples may be : 19551231 (%Y%m%d) or 20210216154500 (%Y%m%d%H%M%S). As you can see, the format may vary.
I'm looking for a way to convert all these different strings to a unique DatetimeWithNanoseconds format.
I know I can convert a timestamp to DatetimeWithNanoseconds using integers like this: DatetimeWithNanoseconds(2020, 6, 22, 17, 1, 30, nanosecond=0).
Does that means that I have to manually parse every string I get to get the relevant integers ? Is there a better way to do this ? Like the way the function strptime works (using strings like %Y%m%d to determine the layout of the string)
I learned that from a
datetimeformat it is easy to extract hours for example just by callingdate.hour(same for year, month, etc).Knowing this, the way to convert a string to a DatetimeWithNanoseconds format takes these 2 easy steps: