DevLab
Time

Unix Timestamps Explained

Everything you need to know about Unix time — what it is, how it works, and common pitfalls.

What is a Unix Timestamp?

A Unix timestamp is the number of seconds that have elapsed since January 1, 1970, at 00:00:00 UTC (the "Unix epoch"). It's the most common way to represent a point in time in computing because it's timezone-independent, a single integer, and trivially comparable.

For example, the Unix timestamp 1700000000 represents November 14, 2023, at approximately 22:13 UTC.

Why Seconds Since 1970?

When Unix was developed in the late 1960s and early 1970s, the team chose January 1, 1970 as the epoch because it was recent, round, and easy to work with. The choice was somewhat arbitrary — other systems use different epochs (e.g., Windows uses January 1, 1601).

Milliseconds vs. Seconds

JavaScript uses milliseconds: Date.now() returns the number of milliseconds since epoch. Most other languages and systems use seconds. Always check which unit an API expects — a common bug is passing milliseconds where seconds are expected, resulting in dates in the year 33000.

The Year 2038 Problem

Traditional Unix time uses a 32-bit signed integer, which can hold values up to 2,147,483,647. That number corresponds to January 19, 2038, at 03:14:07 UTC — after which 32-bit systems overflow. Modern 64-bit systems don't have this problem, but embedded systems and legacy code may.

Working with Timestamps

In JavaScript: Math.floor(Date.now() / 1000) gives the current Unix timestamp in seconds.

To convert a timestamp back to a Date: new Date(timestamp * 1000).

Always store and transmit times in UTC, then convert to local time only for display. This prevents timezone-related bugs in multi-region applications.

Practice with these tools

More Learning Topics

RegexRegex Basics: A Complete Beginner's GuideRegexRegex Special Characters: Complete ReferenceRegexRegex Groups and Captures ExplainedRegexRegex Quantifiers: Complete GuideCSSCSS Selectors: The Complete GuideCSSCSS Specificity: Why Your Styles Aren't ApplyingJSONJSONPath Syntax: Query JSON Like XPathEncodingBase64 Encoding ExplainedEncodingJWT Structure and How It WorksEncodingJWT vs Session Tokens: Which Should You Use?EncodingJWT Refresh Tokens ExplainedCryptoHash Functions Explained: MD5, SHA-256, and When to Use EachEncodingURL Encoding Explained: What %20 Actually MeansJSONJSON Schema Explained: Validate Your JSON DataJSONJSON vs YAML: Which Should You Use?JSONJSON.stringify and JSON.parse: Edge Cases You Should KnowRegexRegex Lookahead and Lookbehind: Match Without ConsumingRegexRegex for Email Validation: The Right ApproachCSSThe CSS Box Model: margin, padding, border, and contentCSSFlexbox vs CSS Grid: When to Use EachCSSCSS Custom Properties (Variables) ExplainedTimeISO 8601 Explained: The Right Way to Format DatesTimeUnix Timestamps vs ISO 8601: Which to Use in Your API?EncodingUTF-8 Explained: How Computers Store TextTextCORS Explained: Why Your API Call is BlockedTextHTTP Status Codes: A Practical Developer GuideRegexNamed Capture Groups in Regex: Clean ExtractionsColorsColor Spaces Explained: RGB, HSL, HEX, and BeyondColorsColor Contrast for Developers: WCAG Rules and How to CheckNumbersNumber Bases Explained: Binary, Octal, Decimal, and HexNumbersBitwise Operations for Web DevelopersHTMLHTML Semantic Elements: A Complete ReferenceTextText Encoding for Developers: ASCII, UTF-8, and UnicodeRegexWhat is Regex? Complete Guide for DevelopersJSONJSON Format Explained: Structure, Syntax, and Common ErrorsEncodingHow JWT Works: Header, Payload, Signature DecodedHTMLHow to Convert Any Website to Markdown (for LLMs, RAG & Docs)TextPreparing Website Content for RAG: Clean Markdown Pipelines