Epoch in Wolfram Language
A common requirement in programs is getting the number of seconds, milliseconds, or nanoseconds since the Unix epoch. Here’s how to do it in Wolfram Language.
In Wolfram Language, we use AbsoluteTime[]
to get the current time. We can then perform calculations to convert this to Unix time (seconds, milliseconds, or nanoseconds since the Unix epoch).
To get the Unix timestamp, we subtract the absolute time of the Unix epoch (January 1, 1970, 00:00:00 UTC) from the current time.
For milliseconds and nanoseconds, we multiply this difference by 1000 and 1000000000 respectively.
We can also convert Unix timestamps back to Wolfram Language dates using AbsoluteTime[]
and DateString[]
.
Here’s an example of what the output might look like:
Note that the exact output will depend on when you run the code.
Next, we’ll look at another time-related task: time parsing and formatting.