2

I found the time format below on kickstarter website:

2015-10-02T20:40:00-04:00
2015-10-19T19:02:40-04:00
2015-09-26T18:53:30-04:00

But I have no idea what's this format? Does it has timezone?

I use python, so I want to know how can I convert it to Python time format?

And I found a nodejs project (source code below) which can convert to string like 1441424612000.

timeEnd: function ($) {
    var endTimeStr, date, endTimeInMillis;

    endTimeStr = $('#project_duration_data').attr('data-end_time');
    date = new Date(endTimeStr);
    endTimeInMillis = date.getTime();

    return endTimeInMillis;
},

What is this time format? Can Python do this?

Yaroslav Admin
  • 13,880
  • 6
  • 63
  • 83
user2492364
  • 6,543
  • 22
  • 77
  • 147
  • 2
    https://en.wikipedia.org/wiki/ISO_8601 – JimmyB Sep 15 '15 at 14:08
  • 1
    Yes, that is definitely standard ISO-8601 time format, and your long number date is a JavaScript timestamp (Unix timestamp * 1000). – brandonscript Sep 15 '15 at 14:09
  • 2
    possible duplicate of [How do I translate a ISO 8601 datetime string into a Python datetime object?](http://stackoverflow.com/questions/969285/how-do-i-translate-a-iso-8601-datetime-string-into-a-python-datetime-object) – brandonscript Sep 15 '15 at 14:11

3 Answers3

1

If you have access to the dateutil package, your job is easy:

>>> import dateutil.parser
>>> dateutil.parser.parse('2015-09-26T18:53:30-04:00')
datetime.datetime(2015, 9, 26, 18, 53, 30, tzinfo=tzoffset(None, -14400))
Zachary Cross
  • 2,298
  • 1
  • 15
  • 22
  • I have a question about ````-04:00````?? is it timezone?? Why ````tzinfo```` shows ````None````?? – user2492364 Sep 15 '15 at 14:57
  • As pointed out in the comment below, it's timezone UTC -04:00. Which, is US Eastern time during daylight savings time, and the Atlantic timezone during standard time. – Zachary Cross Sep 15 '15 at 15:02
0
new Date('2015-10-02T20:40:00-04:00').getTime() 
result 1443832800000

in python

import datetime
datetime.datetime.fromtimestamp(1443832800000/1000.0)
datetime.datetime(2015, 10, 3, 3, 40)
comalex3
  • 2,497
  • 4
  • 26
  • 47
0

I deleted TZ format before parse

from datetime import datetime

t1 = '2015-10-02T20:40:00-04:00'
t2 = '2015-10-19T19:02:40-04:00'
t3 = '2015-09-26T18:53:30-04:00'

date1 = datetime.strptime(t1.replace(' ', '')[:-6], '%Y-%m-%dT%H:%M:%S')
date2 = datetime.strptime(t2.replace(' ', '')[:-6], '%Y-%m-%dT%H:%M:%S')
date3 = datetime.strptime(t3.replace(' ', '')[:-6], '%Y-%m-%dT%H:%M:%S')
print(date1)
print(date2)
print(date3)

timestamp1 = time.mktime(date1.timetuple())
timestamp2 = time.mktime(date2.timetuple())
timestamp3 = time.mktime(date3.timetuple())
print(timestamp1)
print(timestamp2)
print(timestamp3)

You can probe here: https://repl.it/BIOM/1

albertoiNET
  • 1,280
  • 25
  • 34