So what I have is a time string which shows the time as h:m:s.ms
But the problem is that I want to covert them to timestamp values it shows NaN
values.
I am using Date.parse()
to convert the time into timestamp.
Here is the code that I have tried.
var date;
function myFunction() {
var d = new Date();
var h = addZero(d.getHours(), 2);
var m = addZero(d.getMinutes(), 2);
var s = addZero(d.getSeconds(), 2);
var ms = addZero(d.getMilliseconds(), 3);
var maindate = h + ":" + m + ":" + s + "." + ms ;
var datestring = Date.parse(maindate)
var data = Math.random(0,1);
console.log("Date : ", maindate) ;
console.log("Data : ", data);
}
myFunction();
You can see the date
and data
in the console window.
the date
variable here shows NaN Value.
Please tell me what I am doing wrong.