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?

3

3 Answers 3

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))
Sign up to request clarification or add additional context in comments.

2 Comments

I have a question about -04:00?? is it timezone?? Why tzinfo shows None??
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.
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)

Comments

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

2 Comments

what about -04:00?? is it timezone??
Yes, it is the timezone timezone UTC -04:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.