Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
Where in the ECMAScript spec for the Date() constructor does the time value get converted to epoch time?

I understand that an ECMAScript date just stores a time value in epoch time (the number of milliseconds since midnight on 1 January 1970 UTC).

But looking over the algorithm for the Date() constructor, I only see where the argument values are converted to milliseconds; I don't see where the millisecond value is converted to epoch time. Where does that step happen?

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

The Date constructor algorithm calls MakeDay, which returns the number of days since epoch for the argument values. MakeDate then does convert that number of days to the number milliseconds by simple multiplication.
MakeDay contains the following step:

  1. Find a finite time value t such that YearFromTime(t) is ym and MonthFromTime(t) is mn and DateFromTime(t) is 1๐”ฝ;

This is a rather obscure definition, using the operations defined in 21.4.1.3 "Year Number". There we can find the formula

DayFromYear(y) = ๐”ฝ(365 ร— (โ„(y) - 1970) + floor((โ„(y) - 1969) / 4) - floor((โ„(y) - 1901) / 100) + floor((โ„(y) - 1601) / 400))

This comes out to have "day 0" as the first day of 1970.

But rather than deriving that from this formula, we can just read 21.4.1.1 "Time Values and Time Range":

The exact moment of midnight at the beginning of 1 January 1970 UTC is represented by the time value +0๐”ฝ.

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!