Convert a Date to a Unix Timestamp
Published July 16, 2026By Samson PG
Epoch → date is common. Date → epoch is the inverse: pick the timezone of the wall clock you typed, then choose seconds or milliseconds.
A Unix timestamp is an instant since 1970-01-01T00:00:00Z. Going from a human date to that integer is the inverse of formatting an epoch as a string: you must know whether the clock you typed was UTC or local, and whether the API wants seconds or milliseconds.
The two decisions that matter
| Decision | Why it bites |
|---|---|
| UTC vs local input | Same “15:00” is a different instant in IST vs UTC |
| Seconds vs ms output | 10-digit vs 13-digit values break APIs |
The integer itself has no timezone inside it. Timezone only affects how you interpret the calendar fields you entered.
Practical workflow
- Write the date/time you mean (include offset or say “UTC” / “local”).
- Convert to an absolute instant.
- Emit seconds (
Math.floor(ms / 1000)) or milliseconds (Date.getTime()style) to match the consumer. - Round-trip: convert the integer back and confirm the same wall clock in the intended zone.
Example mindset: “2026-07-16 09:00 in Asia/Kolkata” is not the same epoch as “2026-07-16 09:00 UTC.”
Common mistakes
- Treating a local wall time as UTC (off by your offset, e.g. 5:30 in IST).
- Sending milliseconds to an API that documents Unix seconds.
- Parsing
YYYY-MM-DDas UTC in one language and local midnight in another. - Forgetting that epoch is timezone-agnostic — only display strings carry zones.
Use TryDevSnip Timestamp Converter
TryDevSnip Timestamp Converter converts human dates ↔ Unix epoch in the browser, with a live clock for sanity checks. Nothing is uploaded.
Also see: seconds vs milliseconds and UTC vs local display.
Privacy one-liner: conversion happens on your device.
FAQ
Does flying change the timestamp for “now”?
No. “Now” is the same instant; only formatted local time changes.
Should APIs store epoch or ISO strings?
Either works if the unit/zone rules are documented. Many systems store UTC ISO or epoch seconds and localize only in the UI.
Why is my converted epoch off by one day?
Often a midnight parse in UTC vs local, or a missing offset on a date-only string.
Fractional seconds?
Some databases store sub-second epochs. Truncate or round explicitly for integer APIs.