-1

I was trying the following code:

time.mktime(datetime.datetime.strptime("2016-10-17 02:35:01+00:00",
                                       "%Y-%m-%d %H:%M:%S %z"))

It was returning the error:

ValueError: time data '2016-10-17 02:35:01+00:00' does not match format '%Y-%m-%d %H:%M:%S %z'

martineau
  • 119,623
  • 25
  • 170
  • 301
  • `Doesn't match` what is the output you want? We need details in your question in order to answer – techydesigner Oct 17 '16 at 05:41
  • 2
    you have space before `%z` but parsed time doesn't have it – furas Oct 17 '16 at 05:45
  • I was trying the following code time.mktime(datetime.datetime.strptime("2016-10-17 02:35:01+00:00" ,"%Y-%m-%d %H:%M:%S %z")) It was returning the error ValueError: time data '2016-10-17 02:35:01+00:00' does not match format '%Y-%m-%d %H:%M:%S %z' – Josemon Maliakal Oct 17 '16 at 05:46
  • please give the correct format for converting 2016-10-17 02:35:01+00:00 – Josemon Maliakal Oct 17 '16 at 05:46
  • 1
    It's always helpful to include the stack trace or error message you're seeing. Even better, provide an [MCVE](http://stackoverflow.com/help/mcve) we can run directly. – dimo414 Oct 17 '16 at 05:46
  • remove space between `%S` and `%z` - `%Y-%m-%d %H:%M:%S%z` – furas Oct 17 '16 at 05:47
  • removed space returns the following error removed ValueError: time data '2016-10-17 02:35:01+00:00' does not match format '%Y-%m-%d %H:%M:%S%z' – Josemon Maliakal Oct 17 '16 at 05:49
  • Please **EDIT** your post and keep important info out of the comments section – techydesigner Oct 17 '16 at 05:51

1 Answers1

1

If you are not very familiar with the datetime directives, I will suggest you to use dateutil.parser instead. For example:

>>> import dateutil.parser
>>> s = '2016-10-17 02:35:01+00:00'
>>> my_date = dateutil.parser.parse(s)
>>> my_date
datetime.datetime(2016, 10, 17, 2, 35, 1, tzinfo=tzutc())
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126