Going the other direction β€” from a readable date to a Unix timestamp β€” is what you do when you're setting up a JWT expiration, scheduling a cron job, or populating a database field that expects epoch seconds. Humans write "December 31, 2026, midnight UTC"; computers want 1798761600. The conversion is simple in code and instant with the right tool.

Here's what's happening under the hood and where to watch for gotchas.

How the Conversion Works

A Unix timestamp counts seconds from January 1, 1970, 00:00:00 UTC. To convert a date to a timestamp, you compute the elapsed seconds between the epoch and that date. Most programming languages have a built-in that does this in one line:

  • JavaScript: Math.floor(new Date('2026-12-31T00:00:00Z').getTime() / 1000) β€” note the divide by 1000, because JS returns milliseconds.
  • Python: int(datetime(2026, 12, 31, tzinfo=timezone.utc).timestamp())
  • SQL: EXTRACT(EPOCH FROM TIMESTAMP '2026-12-31 00:00:00')

The JavaScript Milliseconds Trap

JavaScript's Date.getTime() returns milliseconds, not seconds. If you forget to divide by 1000, your timestamp will be 1000x too large and decode to a date hundreds of years in the future. This is the single most common timestamp bug in web development. The fix is always the same: divide by 1000 before storing or sending.

Time Zones Matter More Going This Direction

When you convert a timestamp to a date, the time zone is a display choice. But when you convert a date to a timestamp, the time zone changes the answer. "December 31, 2026, midnight" is a different instant depending on whether you mean midnight UTC, midnight Eastern, or midnight Pacific. Always specify the time zone (or use UTC) when generating timestamps, or you'll create subtle bugs that only surface for users in other zones.

Where Date-to-Timestamp Conversion Shows Up

  • JWT tokens: The exp (expiration) and iat (issued at) claims are Unix timestamps.
  • Cron jobs: Scheduled tasks often reference specific instants as epoch seconds.
  • Database records: Created-at and updated-at fields frequently store timestamps.
  • API requests: Some APIs accept since or until parameters as timestamps.

Convert Any Date to a Timestamp

Our Unix Timestamp Converter goes both directions β€” enter a readable date and time (specifying the time zone or UTC) and you get the epoch seconds value, ready to paste into a token, cron expression, or database query. It also gives you the milliseconds value for JavaScript, so you don't have to remember the Γ—1000.