Last updated
What Is Unix Epoch Time?
Unix epoch time (also called Unix timestamp or POSIX time) is the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC — the "Unix epoch." It's the most widely used time representation in computing because it's a simple integer, timezone-independent, and easy to compare and calculate with.
Epoch Time Formats
| Format | Example | Precision |
|---|---|---|
| Unix seconds | 1742601600 | 1 second |
| Unix milliseconds | 1742601600000 | 1 millisecond |
| Unix microseconds | 1742601600000000 | 1 microsecond |
| ISO 8601 | 2026-03-22T00:00:00Z | 1 second (or ms) |
| RFC 2822 | Sun, 22 Mar 2026 00:00:00 +0000 | 1 second |
Conversion in JavaScript
JavaScript
// Current epoch time
const nowSeconds = Math.floor(Date.now() / 1000);
const nowMs = Date.now();
// Epoch to Date
function epochToDate(epoch) {
// Auto-detect seconds vs milliseconds
const ms = epoch > 1e10 ? epoch : epoch * 1000;
return new Date(ms);
}
// Date to epoch
function dateToEpoch(date, unit = 'seconds') {
const ms = date instanceof Date ? date.getTime() : new Date(date).getTime();
return unit === 'ms' ? ms : Math.floor(ms / 1000);
}
// Format epoch as human-readable
function formatEpoch(epoch, timezone = 'UTC') {
const date = epochToDate(epoch);
return date.toLocaleString('en-US', {
timeZone: timezone,
year: 'numeric', month: 'long', day: 'numeric',
hour: '2-digit', minute: '2-digit', second: '2-digit',
timeZoneName: 'short'
});
}
console.log(formatEpoch(1742601600));
// → 'March 22, 2026 at 12:00:00 AM UTC'