Unix Timestamp Help

So wanted to try to convert Unix Time Stamps not be using keywords or shortcuts. I wanted to have multiple loops that subtract from the millisecond (year worth), then add to, for instance, a year variable.

   while (date > 31557600) {
        date -= 31557600;

Here is the full code --> https://repl.it/@John_Nicole/LinedObesePinkriverdolphin

Note that i convert it to seconds at line 10.

Everything works fine but the hours. I thought Unix started at 12:00 pm on January 1st, 1970.

    var year = 1970;
    var month = 1;
    var day = 1;
    var hour = 0;
    var minute = 0;
    var second = 0;

Instead of '12:45.40' I get '17:45.40'.

I have no idea why, 60^2 = 3600 seconds in a hour.

Midnight (00:00:00), not 12:00 pm.

1 Like

Even then it reads 17:52.57

5 hours off…

Are you accounting for your time zone? Are you by any chance 5 hours off of UTC?

Im not sure, anyway to check? I used new Date().getTime()

I know new Date() already gives you exactly what my output is, but why wouldn’t it be my local time?

By default that will give you the time in UTC. If you’re in the US on the East Coast, then your local time is 5 hours behind UTC.

Oh okay, so whats the point of it then? Is this just for comparing between your time and UTC?

It gives a location-agnostic datetime. You can have it convert either to the client’s local time (toLocaleString I think) or to a specific timezone (maybe using the same function, but with a parameter. I don’t recall off the cuff).

Okay, thanks