UNIX Timestamp Converter is a free online developer tool to convert between Epoch/UNIX timestamps and datetimes.
What is a UNIX timestamp?
UNIX timestamp is a time system for describing a moment in time in second also known as Epoch timestamp and POSIX timestamp. The UNIX timestamp is the number of seconds that have been counted since the start of January 1, 1970 (UTC) without leap seconds.
Therefore, 1 day in the UNIX timestamp is treated equally as if it has 86,400 seconds which is different from UTC that always includes leap seconds.
The UNIX timestamp is counted simultaneously throughout the world regardless of timezones which means a UNIX timestamp represents the certain moment in second at any place of the world. Therefore, a UNIX timestamp can be converted to any timezone as a result.
The example UNIX timestamp below represents the time 07:52:04 (UTC) on August 17, 2004 while it's also 03:52:04 (America/New York) on August 17, 2004 at the same moment.
1092729124
How to get the current UNIX timestamp
You can easily get the current UNIX timestamp on Linux and macOS just by typing the following command in the terminal. The result based on your system clock will be displayed accordingly.
date +%s
1574913970
In computer programming, there exists the built-in method for getting the current UNIX timestamp in most programming languages so that developers can handle time-related functions with ease.
For instance, the following is how to get the current UNIX timestamp in JavaScript.
const currentTimestamp = Math.floor(Date.now() / 1000); // Get the current UNIX timestamp in milliseconds using the built-in method Date.now(), and then convert it to seconds by dividing it with 1000.
Moreover, you can use Moment.js, one of the most used libraries for manipulating time in JavaScript, to get the current UNIX timestamp in seconds. The result will be an integer representing the current UNIX timestamp based on your system clock.
moment().unix(); // 1574914824
Methods for obtaining Unix timestamps in various programming languages:
Language | Seconds | Milliseconds |
---|---|---|
JavaScript | Math.round(new Date() / 1000) | new Date().getTime() |
Java | System.currentTimeMillis() / 1000 | System.currentTimeMillis() |
Python | int(time.time()) | int(time.time() * 1000) |
Go | time.Now().Unix() | time.Now().UnixNano() / 1e6 |
PHP | time() | (int)(microtime(true) * 1000) |
Ruby | Time.now.to_i | (Time.now.to_f * 1000).to_i |
C# | DateTimeOffset.UtcNow.ToUnixTimeSeconds() | DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() |
Swift | NSDate().timeIntervalSince1970 | NSDate().timeIntervalSince1970 * 1000 |
Objective-C | [[NSDate date] timeIntervalSince1970] | [[NSDate date] timeIntervalSince1970] * 1000 |