-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?

2
  • What format do you want the date? ie. expected result? Commented Mar 14, 2019 at 8: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. Commented Mar 14, 2019 at 8:51

2 Answers 2

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);

Sign up to request clarification or add additional context in comments.

2 Comments

OP says new Date() not works for this format.?
You can't trust anybody ;-)
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'));

4 Comments

Please explain the downvote?
toLocaleDateString() isn't parsing anything here. and OP has already stated that "new Date() not works for this format."
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
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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.