Unix Timestamp Guides by Language
Copy-ready code to get the current Unix time, convert timestamps to dates and back, and format them in every language this site covers. Each guide was run before publishing and shows the real output under every snippet. To check a single value without code, use the Unix timestamp converter.
Scripting Languages
- Python Timestamp: Get and Convert Epoch Time
Python timestamp recipes: read the clock with time.time(), convert epoch values to aware datetime objects and back, handle milliseconds and nanoseconds, and convert whole pandas columns without loops.
- JavaScript Timestamp: Get and Convert Epoch Time
JavaScript timestamp basics: Date.now() milliseconds, converting between Date objects and Unix seconds, formatting with Intl.DateTimeFormat, BigInt for nanoseconds and monotonic timers in Node.js.
Compiled Languages
More in this section soon.
Databases and Spreadsheets
- Excel Epoch to Date Formulas
Excel epoch to date in one formula, plus millisecond timestamps, converting Excel dates back to Unix time, time zone offsets and the Google Sheets EPOCHTODATE function.
Shells and Command Line
More in this section soon.
Whatever stack you use, epoch time in code works the same way underneath: one integer count of seconds or milliseconds since 1970. What changes is how each language spells it. To convert timestamp in programming languages side by side, every guide follows the same order, so you can jump between languages: get the current timestamp, convert a timestamp to a date, convert a date back, handle milliseconds and nanoseconds, and deal with time zones. Pitfalls are explained at the step where they happen, with the actual error message you would see.
Three rules hold in every language. First, Unix time is always UTC, so convert to a local zone only when a person needs to read the value. Second, check the unit: JavaScript and Java count milliseconds, almost everything else counts seconds, and a factor of 1,000 is the most common bug. Third, prefer “aware” date objects that carry their time zone, because naive ones silently take the zone of whatever machine runs the code.
Need a quick answer instead of code? The converter on the homepage detects the unit, shows UTC and local time side by side and converts whole log files at once. For the concepts behind the code, such as why the epoch is 1970 and what happens in 2038, see the learn Unix time section.