RSS Amplifier

Aba Search and Replace blog · Sep 7, 2025

Unix and JavaScript timestamps

0
Sign in to vote or save

abareplace.com

Unix and JavaScript timestamps

7 Sep 2025

Unix time is the number of seconds elapsed since midnight UTC on January 1, 1970. For example, Unix time was 17‍56684800 on September 1, 2025 at midnight UTC. The counter is independent of the time zone, holding the same value at the same moment in different timezones. It is widely used in C and C++ programming languages, databases (MySQL, PostgreSQL, and SQLite), and file systems (ext3, HFS+, and Reiserfs).

The counter is typically stored in a 32-bit signed integer, so it can represent dates from December 13, 1901 to January 19, 2038. In 2038, the counter will reach 231−1 and overflow, which is known as the year 2038 problem. Fortunately, most modern implementations have already switched to 64-bit integers.

Java and JavaScript use the number of milliseconds, not seconds, to represent time since 1970, resulting in a counter with more digits (e.g., 17‍56684800000) that fits in a 64-bit integer. Some other implementations (e.g., Apple File System) count the number of nanoseconds instead.

The Unix developers chose the epoch of January 1, 1970 because they created the first version of Unix in 1970, so they only needed to represent dates after 1970. Other platforms chose a date close to the introduction of the Gregorian calendar, for example, the Windows counter (the FILETIME structure) starts on January 1, 1601 and the UUID version 1 counter starts on October 15, 1582.

You can use the following functions in different programming languages to get the current Unix timestamp value:

  • in C/C++, use time_t timestamp = time(NULL);
  • in PHP, use echo time();
  • in Python, use:
  • import time, math
    print(math.ceil(time.time()))
        
  • in JavaScript, use Math.ceil(Date.now() / 1000);
  • in Java, use long timestamp = System.currentTimeMillis() / 1000;
  • in Go, use:
  • import "time"
    timestamp := time.Now().Unix();
    
  • in MySQL, use select unix_timestamp();
  • in PostgreSQL, use select ceil(extract(epoch from current_timestamp));
  • in SQLite, use select strftime('%s');

Decode Unix timestamp

Aba Search and Replace can convert Unix/JavaScript timestamps to a date in popular formats including ISO 8601 / RFC 3339, RFC 1123 / RFC 7231, and the Windows system format. It can also perform the reverse conversion and generate the current timestamp.

Aba Search and Replace screenshot

Stop pasting your data into dubious cloud-based tools. Aba Search and Replace is your Swiss army knife for regular expression search, fast and safe updates across multiple files, and various conversions, with all your data staying on your computer. Built for power users, developers, testers, and analysts. Hand-coded in the EU.

Read the original on abareplace.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.