0

I have an input value of a time specifically formatted HH:MM is there way I can convert it to a javascript valid date for example:

Time is: 10:20

Valid javascript time would be: Mon Aug 15 2016 10:20:00

Cedric
  • 1,236
  • 2
  • 18
  • 35
  • http://stackoverflow.com/questions/14638018/current-time-formatting-with-javascript please check this, it may helps – AftabHafeez Aug 15 '16 at 07:10

1 Answers1

4
var timeString = "10:20:51";

var timeStringArray = timeString.split(':');
var hours = timeStringArray[0];
var minutes = timeStringArray[1];
var seconds = timeStringArray[2];

var now = new Date();
now.setHours(hours);
now.setMinutes(minutes);
now.setSeconds(seconds);

console.log(now);

This just changes the hours/minutes component of the current time though

derp
  • 2,300
  • 13
  • 20