-1

What is the purpose/use of the Number() and getTime() methods returning dates to milliseconds since 1.1.1970?

Number()

getTime()

xbot668
  • 3
  • 2
  • That's the Unix epoch. It's a commonly used reference point in time. – Jonathan Lam May 09 '18 at 01:59
  • 1
    I'm inclined to close this as a duplicate of https://stackoverflow.com/q/1090869/497418. – zzzzBov May 09 '18 at 02:01
  • See https://en.wikipedia.org/wiki/Unix_time or the link above – Jonathan Lam May 09 '18 at 02:01
  • It's an easy way to compute date/time! Imagine that you need to compare two dates, it's easier to compare it in epoch time then in the `yyyy-mm-dd` format, agree? – Elias Soares May 09 '18 at 02:03
  • @EliasSoares Completely disagree. ISO 8601 date strings in UTC can be compared directly. The natural lexicographical order that string comparison does gives a proper ordering of time. Unix time doesn't have that property (nor can it easily be compared as numbers). Some values are ambiguous, such as `915148800500` which occurred twice because of a leap second and maps to both `1999-01-01T00:00:00.500Z` and `1998-12-31T23:59:60.500Z` in ISO 8601 format. – Paul May 09 '18 at 02:10
  • @Paulpro what is easier for a computer? Compare a if a number is greater then another, or compare strings lexicographically? Also try to add 30 days in a ISO8601 string, again, what's easier for a computer? Probably that was one of the reasons for using it in the past, where processor time, memory and program memory was very relevant. – Elias Soares May 09 '18 at 02:15
  • `1999-01-01T00:00:00.000Z` comes after `1998-12-31T23:59:60.500Z`, so comparing as strings gives the right result: `'1999-01-01T00:00:00.000Z' > '1998-12-31T23:59:60.500Z'`, but their unix time equivalents give the wrong comparison result (`915148800000 < 915148800500`). – Paul May 09 '18 at 02:15
  • @EliasSoares I did not realize that when you said "it's easier to compare it in epoch time then in the `yyyy-mm-dd` format", you meant easier specifically for a computer and not for a human. Ambiguity and incorrect results aside, it is definitely easier for a computer to compare numbers than strings. I will not argue with that. – Paul May 09 '18 at 02:17
  • That's the point. I think that in that epoch, the unix time standard was a way to handle datetime in a faster way, though it's downsides. – Elias Soares May 09 '18 at 02:20

1 Answers1

0

This is a common convention used in programming as a standard to represent dates, that's free of timezone information and understandable in all situations.

To pull a quote from Wikipedia

Epochs are generally chosen to be convenient or significant by a consensus of the time scale's initial users, or by authoritarian fiat. The epoch moment or date is usually defined by a specific clear event, condition, or criterion—the epoch event or epoch criterion—from which the period or era or age is usually characterized or described.

Epoch Definition on Wikipedia

Another SO post that goes into better detail

JamesWatling
  • 1,175
  • 1
  • 9
  • 17