var date = new Date().toTimeString()
console.log(date)
The above code output is this String : 21:27:52 GMT+0430 (India Daylight Time)
how to convert this string to Date or Number
var date = new Date().toTimeString()
console.log(date)
The above code output is this String : 21:27:52 GMT+0430 (India Daylight Time)
how to convert this string to Date or Number
You are printing time by using the toTimeString()
method.
I believe you are looking for new Date().toLocaleDateString()
for the date string. The output is 3/24/2020
If you want to play around more, feel free to explore the Conversion Getter section of this documentation page. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date