Unix timestamp code guides
Copy-ready code for getting, converting and formatting Unix time in 30 languages, databases and spreadsheets.
Each guide covers the same five things: getting the current Unix time, converting a timestamp to a date, converting a date back, handling timezones, and the mistakes people make. Every snippet follows the official documentation, which is linked at the bottom of each guide.
The first thing to check is the unit. Python's time.time(), PHP's time(), Ruby's Time.now.to_i, date +%s in Bash and the SQL UNIX_TIMESTAMP functions return seconds. JavaScript's Date.now(), Java's System.currentTimeMillis() and Dart's millisecondsSinceEpoch return milliseconds. Pass seconds to a milliseconds API and you get a date in January 1970; pass milliseconds to a seconds API and the date lands tens of thousands of years in the future.
Languages
Databases
Data
Spreadsheets
Looking for an ID format rather than a language? The universal decoder reads UUIDs, ULIDs, snowflakes, ObjectIds and JWTs.
Last updated: