-1

I'm new to javascript but I want to parse this date.

2019-03-04T06:20:30.000

How can I do this?

Date.parse()or new Date() not works for this format.

Should I have to change this into string and use regular expression?

O.O
  • 1,389
  • 14
  • 29
Jin
  • 924
  • 1
  • 9
  • 34
  • What format do you want the date? ie. expected result? – O.O Mar 14 '19 at 08:49
  • `Date.parse()` and `new Date()` should both work. What are you expecting this date to be? As an ISO date this represents 4th march. – Liam Mar 14 '19 at 08:51

2 Answers2

1

This is actually supported via javascript. Have a look at the code below.

var dateString = "2019-03-04T06:20:30.000";

var dateObject = new Date(dateString);

alert(dateObject);
jPO
  • 2,502
  • 1
  • 17
  • 26
0

Try .toLocaleDateString()

console.log(new Date('2019-03-04T06:20:30.000').toLocaleDateString('en-GB'));
console.log(new Date('2019-03-04T06:20:30.000').toString('en-GB'));
O.O
  • 1,389
  • 14
  • 29
  • Please explain the downvote? – O.O Mar 14 '19 at 08:53
  • `toLocaleDateString()` isn't parsing anything here. and OP has already stated that *"new Date() not works for this format."* – Liam Mar 14 '19 at 08:54
  • 1
    Have you tried running the snippet? This is the standard functionality in javascript. If it doesn't work, then the OP is doing something else wrong. But the answer is not incorrect. @OlayinkaO here, have my upvote – jPO Mar 14 '19 at 08:56
  • I don't disagree but re-iterating what the OP already knows doesn't actually answer the question. It's a bad question, adding bad answers doesn't help. Anyway it's closed now – Liam Mar 14 '19 at 08:59