Domanda

I have a bunch of human-readable dates and times (to be specific, the default format in nginx logs) that I wish to convert to Unix timestamps. The format is like this:

04/Dec/2013:18:56:05 +0000

What's the most reliable way of doing this? Are there any libraries I can use for this purpose?

È stato utile?

Soluzione

I think you are looking for datetime.strptime.

From the doc link

The datetime.strptime() class method creates a datetime object from a string representing a date and time and a corresponding format string.

Call it like

datetime.strptime(date_string, format)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top