Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  142] [ 3]  / answers: 1 / hits: 42747  / 12 Years ago, sat, february 16, 2013, 12:00:00

I need to parse dates in JavaScript. The format is



[2 digits day]/[2 digits month]/[4 digits year] [2 digits hour (24 mode)]:[2 digits minute]



For example, 16/02/2013 21:00


But if I do new Date('16/02/2013 21:00').toString(), it gives 'Wed Apr 02 2014 21:00:00 GMT+0200 (Hora de verano romance)'.


I guess that's because my dates don't follow IETF RFC 2822 Date and Time Specification. Then, I should convert my string, and I want to convert it to the most similar compliant format (because it should be easier to convert). But https://www.rfc-editor.org/rfc/rfc2822#page-14 is hard to understand, so I don't know which is the most similar format.


Is there a list with examples of the allowed formats?


More From » date

 Answers
3

MSDN has several examples of valid date formats:



document.writeln((new Date(2010)).toUTCString()); 

document.writeln((new Date(2010-06)).toUTCString());

document.writeln((new Date(2010-06-09)).toUTCString());

// Specifies Z, which indicates UTC time.
document.writeln((new Date(2010-06-09T15:20:00Z)).toUTCString());

// Specifies -07:00 offset, which is equivalent to Pacific Daylight time.
document.writeln((new Date(2010-06-09T15:20:00-07:00)).toGMTString());

// Specifies a non-ISO Long date.
document.writeln((new Date(June 9, 2010)).toUTCString());

// Specifies a non-ISO Long date.
document.writeln((new Date(2010 June 9)).toUTCString());

// Specifies a non-ISO Short date and time.
document.writeln((new Date(6/9/2010 3:20 pm)).toUTCString());

// Output:
// Fri, 1 Jan 2010 00:00:00 UTC
// Tue, 1 Jun 2010 00:00:00 UTC
// Wed, 9 Jun 2010 00:00:00 UTC
// Wed, 9 Jun 2010 15:20:00 UTC
// Wed, 9 Jun 2010 22:20:00 UTC
// Wed, 9 Jun 2010 07:00:00 UTC
// Wed, 9 Jun 2010 07:00:00 UTC
// Wed, 9 Jun 2010 22:20:00 UTC


Gotchas



There's a matrix of cross-browser inconsistencies as well.



References




[#80185] Thursday, February 14, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminuniquer

Total Points: 63
Total Questions: 121
Total Answers: 96

Location: Cambodia
Member since Thu, May 21, 2020
4 Years ago
;