user1757703
user1757703

Reputation: 3015

Python Unrecognized time format

What time format is this 2014-06-14T16:46:01.000Z ?

How can I strftime that into human readable form? I don't recognized what the T and Z mean.

Upvotes: 0

Views: 679

Answers (3)

Rachel Gallen
Rachel Gallen

Reputation: 28563

To convert this don't use strftime use date.util

import dateutil.parser
nowdate = dateutil.parser.parse(datestring)

you can also use https://bitbucket.org/micktwomey/pyiso8601

>>> import iso8601
>>> iso8601.parse_date("2007-01-25T12:00:00Z")
datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.Utc>)
>>>

Upvotes: 3

Ashoka Lella
Ashoka Lella

Reputation: 6729

You can't run an strftime as it can be applied only on date objects. But you can convert this string to a dateobject using strftime

from datetime import datetime
date = datetime.strptime("2014-06-14T16:46:01.000Z", "%Y-%m-%dT%H:%M:%S.%fZ")
print date

output

2014-06-14 16:46:01

T and Z are designatiors for time and zone

Upvotes: 2

Roland Smith
Roland Smith

Reputation: 43495

It is a combined date and time representation according to ISO 8601.

Upvotes: 2

Related Questions