1

is there a way to find out in Python the date format code of a string?

My Input would be e.g.:

2020-09-11T17:42:33.040Z

What I am looking for is in this example to get this:

'%Y-%m-%dT%H:%M:%S.%fZ'

Point is that I have diffrent time Formats for diffrent Files, therefore I don't know in Advancce how my datetime code format will look like.

For processing my data, I need unix time format, but to calculate that I need a solution to this problem.

data["time_unix"] = data.time.apply(lambda row: (datetime.datetime.strptime(row, '%Y-%m-%dT%H:%M:%S.%fZ').timestamp()*100))

Thank you for the support!

abc
  • 157
  • 1
  • 13
  • related: [Get the format in dateutil.parse](https://stackoverflow.com/questions/53892450/get-the-format-in-dateutil-parse), and see also [How to use guess datetime format in pandas with UTC](https://stackoverflow.com/questions/65709510/how-to-use-guess-datetime-format-in-pandas-with-utc?noredirect=1#comment116202532_65709510) – FObersteiner Jan 18 '21 at 14:29

0 Answers0