Skip to content
Advertisement

Convert timestamp to “YY/MM/DD” with JS

I need to convert my “80814.89999999851” timestamp to a YY/MM/DD string. I started by doing this:

var prova = info.originalEvent.timeStamp; //this path lead to: 80814.89999999851

var prova2 = new Date(prova);

Now I have it as a datetime (if i’m not mistaken) but i don’t know how to keep just the year/month/day and then convert it to a string. Can someone help me?

Advertisement

Answer

This timestamp is not seconds since unix epoch, its seconds since timeOrigin (most likely time since page was loaded), to convert it to date you need to obtain timeOrigin first. Take a look at this question: Knowing the time origin of event’s timestamp.

https://developer.mozilla.org/en-US/docs/Web/API/Event/timeStamp

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement