💡 Tips Data & Formatting

Unix Timestamp: Developer Tips for Working with Timestamps

Advertisement
📊
Unix Timestamp Converter

Convert Unix timestamps to human dates and back — with timezone support.

Use this tool →

Always store timestamps in UTC in databases

The most common timestamp bug in web applications is storing local times in databases. A timestamp stored as "2024-03-15 09:00:00" without timezone information is ambiguous — it means different things to a server in New York vs London. Store Unix timestamps (integers) or UTC datetime strings (ISO 8601 with Z suffix). Convert to local time only at the display layer, in the user's browser or application. The converter's UTC output is the correct format for database storage.

Use the converter to debug JWT tokens

JWT tokens contain exp (expiry) and iat (issued at) claims as Unix timestamps in seconds. When a JWT is rejected with "token expired", paste the exp value into the converter to see exactly when it expired and calculate how long ago. Compare with the iat to verify the token lifetime was set correctly. See the JWT Decoder to extract these values from a token directly.

JavaScript Date gotchas with timestamps

JavaScript's Date constructor accepts milliseconds: new Date(1700000000000). If you pass seconds by mistake (new Date(1700000000)), you will get a date in January 1970, not 2023. Always multiply by 1000 when constructing a Date from a seconds timestamp: new Date(timestamp * 1000). The converter shows both the seconds and milliseconds values so you can copy the right one for your context.

Calculate time differences with timestamps

Timestamp arithmetic is simpler than date arithmetic. To find the difference between two moments: subtract the earlier timestamp from the later one to get seconds. Divide by 60 for minutes, 3600 for hours, 86400 for days. No calendar logic, no DST complications, no timezone conversions needed. The reference table shows common offsets (1 hour = 3600, 1 day = 86400, 30 days = 2,592,000) for quick reference.

Set JWT expiry times correctly

JWT expiry (exp) is a Unix timestamp in seconds representing when the token should no longer be accepted. To create a token expiring in 1 hour: exp = Math.floor(Date.now() / 1000) + 3600. To create one expiring at end of day: exp = the Unix timestamp for midnight tonight. Use the date-to-timestamp converter to get the exact exp value for a specific future moment.

Click reference table rows to convert them

The reference table at the bottom shows historically significant timestamps and useful relative times (1 hour ago, yesterday, 1 week ago). Click any timestamp value in the table to load it into the converter and see the full date/time details. This is useful for quickly checking context around a specific historical timestamp or understanding what "30 days ago" was as a specific date.

Advertisement
🔧
Use the tool
Unix Timestamp Converter
📖
📖 Full Guide →
Unix Timestamp Converter
❓
Frequently Asked Questions
Common questions about Unix Timestamp Converter

📦 Recommended Resources

Handpicked books and tools — links may earn a small commission at no cost to you.