Converting a Unix Timestamp to Local Time
How Unix time to local time conversion works, what it changes and what it doesn't, and when to keep UTC or an explicit offset instead of a bare local clock reading.
A Unix timestamp is a single number that identifies a moment. Converting it to local time turns that number into a clock reading a person can understand, such as a date, hour and minute in New York or Los Angeles. This review explains what the conversion does, where it helps, where it loses information, and when to keep the raw value or a UTC form.
Is converting Unix time to local time the right choice?
Convert to local time when a person needs to read the moment in their own frame of reference, such as an event start, a log entry being checked by hand, or a delivery window. The main benefit is immediate readability. The main tradeoff is that a local clock reading depends on a time zone, and if that zone is not shown with the result, the reading can be misunderstood or cannot be converted back reliably.
Keep the original timestamp, or an unambiguous UTC form, in these situations:
- Storing values in a database, file or API payload, where the number or a UTC string is the reliable record.
- Sorting, comparing or calculating durations, which are simpler and safer on the raw value.
- Sharing with readers in several time zones, where one person's local time is another person's wrong time.
- Any case where the destination may strip or ignore the time zone label.
In short, local time works well as a display layer. It is a poor replacement for the stored value.
What the conversion actually changes
Unix time counts seconds elapsed since 00:00:00 UTC on January 1, 1970, and it does not count leap seconds. The number has no time zone because it refers to the same instant everywhere. Converting it to local time does not change that instant. It applies a time zone's rules for that date, including its offset from UTC and whether daylight saving time was in effect, and then formats the result as a calendar date and clock time.
Two layers are involved, and keeping them separate prevents most mistakes:
- The stored value: the timestamp itself, which stays the same whoever views it.
- The presentation: the local date and time string, which differs by time zone, date format and language settings.
The word "local" is also ambiguous. It can mean the time zone of the device running the conversion, the zone set in a browser or account, or a zone the user picks explicitly. Server-side code often runs in UTC, so its "local" output may not match what a reader expects. Naming the zone explicitly removes this uncertainty.
A worked example
The timestamp 1700000000 corresponds to 22:13:20 UTC on November 14, 2023. On that date standard time applied in the continental US, so the same instant reads differently by zone:
| Time zone | Offset on that date | Local reading |
| UTC | +00:00 | Nov 14, 2023, 10:13:20 PM |
| America/New_York | −05:00 | Nov 14, 2023, 5:13:20 PM |
| America/Chicago | −06:00 | Nov 14, 2023, 4:13:20 PM |
| America/Los_Angeles | −08:00 | Nov 14, 2023, 2:13:20 PM |
The timestamp 0 shows why the date can shift as well as the hour. It is midnight UTC on January 1, 1970, but 7:00 PM on December 31, 1969 in New York.
Seconds versus milliseconds
Classic Unix timestamps are in seconds and are currently 10 digits long. JavaScript and many web APIs use milliseconds, which are currently 13 digits long. If you pass a millisecond value to a tool that expects seconds, the result lands tens of thousands of years in the future. If you pass a seconds value to a millisecond tool, the result lands in January 1970. Check the digit count before you trust a result.
Converting with code instead of a web page
Standard libraries can do the conversion locally, with an explicit IANA time zone name rather than a fixed offset. A zone name lets the library apply daylight saving rules for the specific date.
// JavaScript (expects milliseconds)
new Date(1700000000 * 1000).toLocaleString("en-US", { timeZone: "America/New_York" });
# Python 3.9+
from datetime import datetime
from zoneinfo import ZoneInfo
datetime.fromtimestamp(1700000000, tz=ZoneInfo("America/New_York")).isoformat()
# '2023-11-14T17:13:20-05:00'
# GNU date (Linux)
TZ="America/New_York" date -d @1700000000
The flags for the date command differ on macOS and BSD systems, so the last example applies only to GNU coreutils. Converting on your own machine also avoids sending values to a third-party site. This review had no evidence about how any particular online converter handles or retains the data entered into it, and a tool's appearance does not answer that question.
Will the result stay readable and usable after copying or sharing?
Plain text copied from a converter keeps its characters. The meaning is less durable than the characters. These are the main ways it degrades:
- Missing zone: "5:13 PM" without a zone or offset is read as the recipient's own local time. Include an offset, such as -05:00, or a zone name.
- Abbreviations: labels like EST or CST are common in the US, but some abbreviations are used for more than one zone worldwide. An IANA name or numeric offset is less ambiguous.
- Daylight saving gaps and repeats: when clocks fall back, one local hour occurs twice. A bare local reading in that hour cannot be mapped back to a single timestamp unless it carries an offset. When clocks spring forward, some local readings never occur at all.
- Date order: 11/04/2023 means November 4 to most US readers and 11 April in many other places. Spelling out the month, or using ISO 8601 (2023-11-04), avoids this.
- Sorting and search: localized strings such as "Nov 14, 2023, 5:13 PM" do not sort in chronological order as text and are hard to filter. ISO 8601 strings in a single offset do sort correctly.
For readers who use assistive technology, a spelled-out date such as "November 14, 2023, 5:13 PM Eastern Time" is generally less ambiguous than a compact numeric form. On web pages, the HTML time element can pair a readable label with a machine-readable datetime attribute. The supplied material contained no tests of how specific screen readers announce timestamps, numeric dates or offsets, so verify this in the screen readers your audience actually uses rather than assuming one rendering applies everywhere.
A dependable pattern for sharing is to show the local reading for people and keep a precise value alongside it. One option is the ISO 8601 string with its offset. Another is the original timestamp.
Limits to keep in mind
- Accuracy depends on the time zone database the tool or system uses. Zone rules change over time, and outdated data can give wrong offsets for affected dates.
- Systems that store Unix time as a signed 32-bit integer cannot represent moments after 03:14:07 UTC on January 19, 2038. Most modern platforms use 64-bit values, but older software and file formats may not.
- Unix time ignores leap seconds, so it is not suited to applications that need them counted.
- This review is based on general, documented behavior of Unix time and common libraries. It does not evaluate any specific converter product, and no measurements or product test results were available.
Bottom line
Converting a Unix timestamp to local time is a safe and useful transformation for display, because it changes only how an instant is presented, not the instant itself. It becomes unreliable once the local string is separated from its time zone or replaces the stored value. Use an explicit zone, show the offset when the text will travel, and keep the timestamp or a UTC form wherever the data will be stored, sorted or reused.