Convert a date string with a time zone to an era

I am trying to convert this date string, including timezone, to an era. (python 2.7)

Mon, 08 Jun 2009 19:37:51 GMT

I tried to do this:

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

The error I am getting is:

ValueError: invalid format string

What is the problem? How can this be fixed?

Thank.

+4
source share
1 answer

Python 3.5using the method timestamp():

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

which gives:

1244489871.0

There are suggestions for use strftime

Literature:

+1
source

Source: https://habr.com/ru/post/1669147/


All Articles