String string in Javascript

0

I'm developing an application in VueJS and on a screen I have two input's of time and are being saved in MongoDB as String. However the input only accepts in the time format and when I click on the grid and the inputs are filled with the data of the object in question the time fields are not filled because they are in String format and need to be converted to time format.

I have already researched something about this but found only functions that convert date and time together, nothing that was just time conversion.

If someone can give me an example of how to do this String conversion in an hour I thank you ...

    
asked by anonymous 06.10.2017 / 14:58

1 answer

2

Using the current date plus the time you need:

var d = new Date();
var year = d.getFullYear();
var month = d.getMonth();
var day = d.getDay();

var hour = '12';
var min = '35';

var reserv = new Date(year,month,day,hour,min)

If you need to use timestamp:

reserv.getTime();
    
06.10.2017 / 15:08