0

In Typescript

new Date("12-03-2018") 

returns me Dec 03 2018.

But I was expecting Mar 12 2018

Is there any way to specify the date format as DD-MM-YYYY, seems it is taking it as MM-DD-YYYY

Jay
  • 9,189
  • 12
  • 56
  • 96
  • Did you mean March 12? "12-03-2018" can't possibly be interpreted as "March 03" –  Mar 13 '18 at 15:54
  • Sorry yes, March 12 – Jay Mar 13 '18 at 15:54
  • 1
    parse string and use values separate `new Date(2018, 2, 12)` – MysterX Mar 13 '18 at 15:54
  • @MysterX Thanks, mate, no other simple way? – Jay Mar 13 '18 at 15:55
  • 1
    [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date): _"The string should be in a format recognized by the Date.parse() method (**[IETF-compliant RFC 2822](http://tools.ietf.org/html/rfc2822#page-14)** timestamps and also a version of **[ISO8601](http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15)**)."_ – Andreas Mar 13 '18 at 15:55
  • 2
    MomentJS lets you parse from a specific format, in a cross-browser consistent way. –  Mar 13 '18 at 15:56
  • @MysterX you mean `new Date(2018, 2, 12)` - month is zero-indexed ;) – phuzi Mar 13 '18 at 15:56
  • @phuzi yep, exactly. comment edited – MysterX Mar 13 '18 at 15:57
  • Please search before you ask. This question has been answered a gazillion times already. – str Mar 13 '18 at 15:57
  • Thanks, guys, moment js helped me. Sorry for duplicate post, I could not find before. – Jay Mar 13 '18 at 16:08

0 Answers0