-3

How to extract time fro a date string in javascript? For reference : date is 2020-03-11T10:00:00 and need to extract 10:00:00

using :let d = new date().toISOString().replace(/^[^:]*([0-2]\d:[0-5]\d).*$/, "$1");
console.log(d);

which returns 10:00

1
  • 1
    Why regex? Why not .split("T") or .slice(), or ... ? Commented Apr 4, 2020 at 15:19

3 Answers 3

1

Try this:

new Date().toISOString().split('T')[1].split('.')[0];
Sign up to request clarification or add additional context in comments.

Comments

1

You could slice the wanted part.

var iso = '2020-03-11T10:00:00',
    time = iso.slice(11, 19);

console.log(time);

Comments

-1

console.log(new Date('2020-03-11T10:00:00').toLocaleTimeString());

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.