17

I'm using an API that returns "1391759952.7056" as a timestamp. I was wondering what the numbers behind the dot mean? As far as I know only 10 characters get used for Epoch time ...

Taapo
  • 1,785
  • 4
  • 18
  • 35
  • 3
    Most likely fractions of seconds. – arkascha Feb 11 '14 at 08:08
  • 2
    It's a number, it means what the numbers after a decimal normally mean in a floating point number. – Barmar Feb 11 '14 at 08:08
  • 1
    Yes, I can see it's a number. I was wondering if it was a widely (or specific) used method - since I can only find examples that show 10 characters for Epoch time. – Taapo Feb 11 '14 at 08:10
  • 2
    Java uses a time with milliseconds since the Epoch; it is often shown with 3 decimal places, but also shown with 13 digits (these days; it wasn't so long ago that the integer time stamps were only 9 digits (2001-09-09 was the switchover day). Some systems provide 6 or even 9 digits after the decimal point; the `gettimeofday()` function provides µs resolution, and `clock_gettime()` provides ns resolution. – Jonathan Leffler Feb 11 '14 at 08:22
  • 2
    It could be one more reason to return "numbers behind the dot", than fractions of seconds: leap seconds, used for UTC and Earth rotation synchronization. Actually the number of seconds in a UTC day is not exactly 86400. Wikipedia gives some explanations about it. – MichaelGoren Feb 11 '14 at 09:03
  • What API? In what language? Is it returned as a string or as a floating-point number? – Keith Thompson Feb 02 '16 at 20:46

2 Answers2

5

If it were 1391759952.705 * 1000 it would be milliseconds. You seem to have one extra decimal! In Java, you would get this (1391759952705) with System.currentTimeMillis(). As a detail, in Java, the biggest range is given by System.nanoTime() - nanoseconds (faster than currentMillis() to my knowledge but not relative to a fixed point in time so it would be more suitable for measuring elapsed times, not the current time).

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Sandman
  • 2,577
  • 2
  • 21
  • 32
5

Definitely fractions of a second, see https://en.wikipedia.org/wiki/ISO_8601

Run a couple of tests from the command line:
$ date -Ins -d@1452550837
2016-01-11T22:20:37,000000000+0000
$ date -Ins -d@1452550837.010
2016-01-11T22:20:37,010000000+0000
$ date -Ins -d@1452550837.000010
2016-01-11T22:20:37,000010000+0000

Tends to be inconvenient when parsing Unix times in Go.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
candita
  • 101
  • 1
  • 3