DEV Community

Sam
Sam

Posted on

Unix Timestamps Explained: A Practical Guide for Developers

If you work with APIs, logs, databases, authentication tokens, or scheduled jobs, you have probably seen numbers like this:

1789056000
Enter fullscreen mode Exit fullscreen mode

That number can represent a date and time using a Unix timestamp.

What Is a Unix Timestamp?

A Unix timestamp represents the number of seconds that have passed since:

January 1, 1970 00:00:00 UTC
Enter fullscreen mode Exit fullscreen mode

This point in time is known as the Unix Epoch.

For example:

0
Enter fullscreen mode Exit fullscreen mode

represents:

1970-01-01 00:00:00 UTC
Enter fullscreen mode Exit fullscreen mode

As time passes, the Unix timestamp increases.


Seconds vs Milliseconds

One common source of bugs is confusing seconds with milliseconds.

A Unix timestamp in seconds may look like:

1789056000
Enter fullscreen mode Exit fullscreen mode

The same type of value in milliseconds may look like:

1789056000000
Enter fullscreen mode Exit fullscreen mode

JavaScript's Date API normally works with milliseconds.

For example:

const timestamp = 1789056000;

const date = new Date(timestamp * 1000);

console.log(date);
Enter fullscreen mode Exit fullscreen mode

We multiply the timestamp by 1000 because:

1 second = 1000 milliseconds
Enter fullscreen mode Exit fullscreen mode

Get the Current Unix Timestamp in JavaScript

Getting the current Unix timestamp is simple:

const timestamp = Math.floor(Date.now() / 1000);

console.log(timestamp);
Enter fullscreen mode Exit fullscreen mode

Date.now() returns the current time in milliseconds.

Dividing it by 1000 converts it to seconds.

Math.floor() removes the decimal portion.


Convert a JavaScript Date to Unix Time

You can also convert any JavaScript Date object into a Unix timestamp.

const date = new Date("2026-09-11T10:00:00Z");

const timestamp = Math.floor(date.getTime() / 1000);

console.log(timestamp);
Enter fullscreen mode Exit fullscreen mode

Here, getTime() returns milliseconds, so we divide the result by 1000.


Convert Unix Time Back to a Date

You can convert a Unix timestamp back into a readable JavaScript date:

const timestamp = 1789056000;

const date = new Date(timestamp * 1000);

console.log(date.toISOString());
Enter fullscreen mode Exit fullscreen mode

This is especially useful when debugging API responses, database records, or logs.


Where Are Unix Timestamps Used?

Unix timestamps appear in many parts of software development:

  • REST APIs
  • JWT tokens
  • Database records
  • Server logs
  • Scheduled jobs
  • Caching systems
  • Authentication sessions
  • Analytics events

For example, a JWT payload might contain:

{
  "iat": 1789056000,
  "exp": 1789059600
}
Enter fullscreen mode Exit fullscreen mode

Here:

iat means Issued At.

exp means Expiration Time.

These values make it easy for applications to determine when a token was created and when it should expire.


Why Are Unix Timestamps Useful?

One major advantage of Unix timestamps is that they represent a specific point in time.

For example, a value like:

11 September 2026, 3:30 PM
Enter fullscreen mode Exit fullscreen mode

can become confusing because the timezone is unclear.

But a Unix timestamp represents the same moment regardless of where the user is located.

Your application can then convert that timestamp into the user's local timezone when displaying it.

This makes Unix timestamps especially useful for:

APIs, distributed applications, databases, authentication systems, and server logs.


A Small Tool I Built

While working with timestamps, I often needed a quick way to convert between Unix timestamps and readable dates.

Opening the browser console every time worked, but it wasn't very convenient.

So I built a Unix Timestamp Converter as part of a project I'm working on called YBS — Your Browser Suite.

👉 Try the Unix Timestamp Converter

It lets you quickly convert between Unix timestamps and readable date/time values directly in your browser.


What Is YBS?

YBS — Your Browser Suite is a collection of small browser-based utilities for common developer tasks.

It currently includes tools for things such as:

  • JSON formatting
  • Regex testing
  • Cron expressions
  • JWT decoding
  • Diff checking
  • Base64 encoding
  • Unix timestamp conversion
  • YAML viewing
  • Word and character counting
  • QR code generation

No signup is required.

I'm continuing to improve the project and add useful tools over time.


What Should I Build Next?

I'm curious what other developers repeatedly search for while coding.

What small developer tool do you wish you had available instantly in your browser?

Let me know in the comments. 👇

Top comments (0)