0

I have a date formated like this: "2018-06-12T13:58:36.663550655Z"

I want be convert this string into a Unix time stamp.

This is my code:

from datetime import datetime
    date = '2018-06-12T14:03:35.306662173Z'
    time = datetime.strptime(date,"%Y-%m-%dT%H:%M:%S.%fZ")
    unixTime = datetime.utcfromtimestamp(time)

When i run it, there's a error:

ValueError: time data '2018-06-12T14:03:35.306662173Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'

Would be nice if someone could help me ! Thanks!

cjnash
  • 1,228
  • 3
  • 19
  • 37
JimStark
  • 1
  • 3

1 Answers1

0

Try stripping the extra info.

Ex:

import time
from datetime import datetime
date = '2018-06-12T14:03:35.306662173Z'
d = datetime.strptime(date[:26],"%Y-%m-%dT%H:%M:%S.%f")
unixTime =  time.mktime(d.timetuple())
print(unixTime)

Output:

1528792415.0
Rakesh
  • 81,458
  • 17
  • 76
  • 113