Transforming string in time in Javascript

Asked

Viewed 1,042 times

0

I am developing an application in Vuejs and on a screen I have two input’s of hour 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 the format time.

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

If anyone can give me an example of how to make this String conversion on time I thank you...

  • Include in your question the input code with your masks.

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();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.