Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need to multiply unix timestamps by 1000 in JavaScript?

I'm sure there's a reason I have to add three zeros to every Unix timestamp in JavaScript in order to get the correct date. Can you tell me why? Is it as simple as milliseconds since the epoch vs. seconds?

like image 295
buley Avatar asked Jan 13 '11 02:01

buley


People also ask

Why Unix epoch is important in for determination of date and time in programming?

Unix Epoch Early Unix engineers picked that date arbitrarily because they needed to set a uniform date for the start of time, and New Year's Day, 1970, seemed most convenient.

What is timestamp in JavaScript?

A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time.

How do you convert UTC to Unix?

We can do this by simply multiplying the Unix timestamp by 1000 . Unix time is the number of seconds that have elapsed since the Unix epoch, which is the time 00:00:00 UTC on 1 January 1970 .


1 Answers

Because Javascript uses milliseconds internally, while normal UNIX timestamps are usually in seconds.

like image 100
deceze Avatar answered Sep 17 '22 18:09

deceze