Date object, which is misnamed since it is really a date+time. Which means it cannot parse a time string
HH:mm:ss without a date, but it can parse a date string.
There are a few options.
- Convert time to a datetime string and parse using
- Use Momentjs
String + Format parsing function.
You can add up any date(
MM-DD-YYYY) and convert the time(
HH:mm:ss) sting to a datetime (
MM-DD-YYYY HH:mm:ss) string.
var timeString = '12:23:00';
var datetime = new Date('1970-01-01T' + timeString + 'Z');
1970-01-01T is a sample date to complete the string, you can any date of your choice but make sure u don't use the date part accidentally.
Here you can parse any date, time or datetime provided you know the format.
moment(<String>, <String>);, this will work with 12 or 24 hour times.
Refer Doc for accepted formats.