4

I'm trying to convert this date string including timezone to epoch time. (python 2.7)

Mon, 08 Jun 2009 19:37:51 GMT

I tried to do so like that:

from dateutil import parser
parser.parse("Mon, 08 Jun 2009 19:37:51 GMT").strftime('%s')

The error I get is:

ValueError: Invalid format string

What is the problem? How can it be fixed?

Thanks.

kinimmm
  • 41
  • 1

1 Answers1

2

Python 3.5 solution using timestamp() method:

from dateutil import parser
print(parser.parse("Mon, 08 Jun 2009 19:37:51 GMT").timestamp())

which yields:

1244489871.0

There are suggestions for not using strftime

References:

  1. Convert python datetime to epoch with strftime
  2. https://dateutil.readthedocs.io/en/stable/examples.html#parse-examples
Community
  • 1
  • 1
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65