convert number to data type time
let time = 19:30; /// this is a number
let time2 = 19:30; /// this is a time
I want to convert numbers to hours and minutes (time)
convert number to data type time
let time = 19:30; /// this is a number
let time2 = 19:30; /// this is a time
I want to convert numbers to hours and minutes (time)
function toGetTime() {
let time = "19:30"; //input time as String
time = time.split(':');
let now = new Date();
var date = new Date(now.getFullYear(), now.getMonth(), now.getDate(), ...time);
var toTime = date.toLocaleTimeString('it-IT')
console.log(toTime)
}
toGetTime();
You may input time as a string not actual numbers. In the code above, it will extract time from the Date and time format of Javascript.
There really is no type time we only have String, Number, Booleans, undefined and null. So if you really want it in a time format it will be a date-time format in the form of String. From here you can extract the time.
You can also reference these links: