E
E
epic_noob2012-10-10 16:32:38
JavaScript
epic_noob, 2012-10-10 16:32:38

Parsing date from ISO 8601

There is a string in ISO format 2005-08-09T18:31:42+03:30
How can I find out from here that the time zone is +03:30?
Is there any library?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
P
Puma Thailand, 2012-10-10
@opium

And the last six letters do not suit you?

I
Ilya Shabanov, 2012-10-10
@ishaba

n8v.enteuxis.org/2010/12/parsing-iso-8601-dates-in-javascript/

B
btd, 2012-10-10
@btd

momentjs.com/docs/#/parsing/

M
Mikhail Davydov, 2012-10-12
@azproduction

You can use date.js or just a regular expression

var rx = /[+-]\d{2}\:?(?:\d{2})?$/;
"2005-08-09T18:31:42+03:30".match(rx); // ["+03:30"]
"2005-08-09T18:31:42+0330".match(rx); // ["+0330"]
"2005-08-09T18:31:42+03".match(rx); // ["+03"]

// Или более правльный формат таймзоны
var rx = /[+-]\d{2}\:?\d{2}$/; //  не включает короткую запись таймзоны 2005-08-09T18:31:42+03 - такие даты так же не парсят браузеры

T
termi, 2012-10-12
@termi

developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

var d = new Date("2005-08-09T18:31:42+03:30")
d.getTimezoneOffset() / 60

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question