-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

Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
Ammie
  • 3
  • 2

3 Answers3

1

You could slice the wanted part.

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

console.log(time);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
1

Try this:

new Date().toISOString().split('T')[1].split('.')[0];
-1

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