Omri Omri - 5 months ago 22
Javascript Question

Issue with Unix time converting to date

I have the following code in Javascript:

//obj.uploadDate = 1466679630387
temp = new Date(obj.uploadDate);
uploadDate = temp.toString('yyyy-MM-dd HH:mm:ss');


For some reason, the value of
uploadDate
is
NaN-NaN-NaN NaN:NaN:NaN
, instead of a formatted date.

What could be the issue?

Answer

Well, i had to convert to number, and now it's works great.

temp = new Date(Number(obj.uploadDate));
uploadDate =  temp.toString('yyyy-MM-dd HH:mm:ss');