<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Allan</title>
    <description>The latest articles on DEV Community by Allan (@allan_2001).</description>
    <link>https://dev.to/allan_2001</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4125658%2Fc24de91a-6321-4a09-9afb-ad75de2aed39.jpg</url>
      <title>DEV Community: Allan</title>
      <link>https://dev.to/allan_2001</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/allan_2001"/>
    <language>en</language>
    <item>
      <title>Unix Timestamp Explained: What Epoch Time Is and How to Convert It</title>
      <dc:creator>Allan</dc:creator>
      <pubDate>Tue, 15 Sep 2026 06:38:16 +0000</pubDate>
      <link>https://dev.to/allan_2001/unix-timestamp-explained-what-epoch-time-is-and-how-to-convert-it-4cbf</link>
      <guid>https://dev.to/allan_2001/unix-timestamp-explained-what-epoch-time-is-and-how-to-convert-it-4cbf</guid>
      <description>&lt;p&gt;If you've worked with APIs, databases, logs, authentication systems or backend applications, you've probably encountered a Unix timestamp.&lt;/p&gt;

&lt;p&gt;You may see values such as:&lt;/p&gt;

&lt;p&gt;1725369600&lt;/p&gt;

&lt;p&gt;At first glance, it looks like a random number. It isn't. A Unix timestamp represents a specific point in time and is widely used by computers to store and exchange dates.&lt;/p&gt;

&lt;p&gt;In this guide, we'll explain what a Unix timestamp is, how Unix time works, the difference between seconds and milliseconds, and how to convert timestamps in JavaScript, Python and Linux.&lt;/p&gt;

&lt;p&gt;What is a Unix timestamp?&lt;/p&gt;

&lt;p&gt;A Unix timestamp is the number of seconds that have elapsed since the Unix epoch.&lt;/p&gt;

&lt;p&gt;The Unix epoch is:&lt;/p&gt;

&lt;p&gt;January 1, 1970 at 00:00:00 UTC&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;0 = January 1, 1970 00:00:00 UTC&lt;/p&gt;

&lt;p&gt;A larger timestamp represents a later point in time.&lt;/p&gt;

&lt;p&gt;Unix timestamps are useful because computers can work with a single numeric value instead of storing dates in different human-readable formats.&lt;/p&gt;

&lt;p&gt;Why do developers use Unix time?&lt;/p&gt;

&lt;p&gt;Unix timestamps are common because they are simple to store, compare and transmit.&lt;/p&gt;

&lt;p&gt;They are frequently used in:&lt;/p&gt;

&lt;p&gt;• REST APIs&lt;br&gt;
• Databases&lt;br&gt;
• Application logs&lt;br&gt;
• JWT tokens&lt;br&gt;
• Authentication systems&lt;br&gt;
• Cloud applications&lt;br&gt;
• Cron jobs and scheduling&lt;br&gt;
• File metadata&lt;br&gt;
• Distributed systems&lt;/p&gt;

&lt;p&gt;For example, comparing two timestamps is straightforward:&lt;/p&gt;

&lt;p&gt;timestamp A &amp;lt; timestamp B&lt;/p&gt;

&lt;p&gt;This means timestamp A occurred before timestamp B.&lt;/p&gt;

&lt;p&gt;Unix timestamp seconds vs milliseconds&lt;/p&gt;

&lt;p&gt;One of the most common timestamp mistakes is confusing seconds with milliseconds.&lt;/p&gt;

&lt;p&gt;A Unix timestamp in seconds might look like:&lt;/p&gt;

&lt;p&gt;1757894400&lt;/p&gt;

&lt;p&gt;A timestamp in milliseconds might look like:&lt;/p&gt;

&lt;p&gt;1757894400000&lt;/p&gt;

&lt;p&gt;Milliseconds are 1,000 times larger because there are 1,000 milliseconds in one second.&lt;/p&gt;

&lt;p&gt;In JavaScript, Date.now() returns milliseconds.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Date.now()&lt;/p&gt;

&lt;p&gt;If you need Unix time in seconds, you can use:&lt;/p&gt;

&lt;p&gt;Math.floor(Date.now() / 1000)&lt;/p&gt;

&lt;p&gt;When working with an API, always check whether it expects seconds or milliseconds.&lt;/p&gt;

&lt;p&gt;How to get the current Unix timestamp in JavaScript&lt;/p&gt;

&lt;p&gt;JavaScript's Date object can be used to work with Unix time.&lt;/p&gt;

&lt;p&gt;Current timestamp in milliseconds:&lt;/p&gt;

&lt;p&gt;Date.now()&lt;/p&gt;

&lt;p&gt;Convert it to seconds:&lt;/p&gt;

&lt;p&gt;Math.floor(Date.now() / 1000)&lt;/p&gt;

&lt;p&gt;You can also convert a Unix timestamp back into a JavaScript Date:&lt;/p&gt;

&lt;p&gt;const timestamp = 1757894400;&lt;br&gt;
const date = new Date(timestamp * 1000);&lt;/p&gt;

&lt;p&gt;console.log(date);&lt;/p&gt;

&lt;p&gt;How to convert Unix timestamps in Python&lt;/p&gt;

&lt;p&gt;Python provides the time module for working with Unix timestamps.&lt;/p&gt;

&lt;p&gt;Get the current Unix timestamp:&lt;/p&gt;

&lt;p&gt;import time&lt;br&gt;
print(int(time.time()))&lt;/p&gt;

&lt;p&gt;Convert a timestamp into a readable UTC date:&lt;/p&gt;

&lt;p&gt;from datetime import datetime, timezone&lt;/p&gt;

&lt;p&gt;timestamp = 1757894400&lt;br&gt;
date = datetime.fromtimestamp(timestamp, tz=timezone.utc)&lt;/p&gt;

&lt;p&gt;print(date)&lt;/p&gt;

&lt;p&gt;How to get Unix time on Linux&lt;/p&gt;

&lt;p&gt;Linux systems make it easy to work with Unix timestamps from the command line.&lt;/p&gt;

&lt;p&gt;To get the current timestamp:&lt;/p&gt;

&lt;p&gt;date +%s&lt;/p&gt;

&lt;p&gt;To convert a Unix timestamp into a readable date:&lt;/p&gt;

&lt;p&gt;date -d @1757894400&lt;/p&gt;

&lt;p&gt;On systems with GNU date, this is a convenient way to inspect timestamps while troubleshooting logs and scripts.&lt;/p&gt;

&lt;p&gt;Common Unix timestamp mistakes&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Seconds vs milliseconds
&lt;/h3&gt;

&lt;p&gt;This is probably the most common mistake.&lt;/p&gt;

&lt;p&gt;If an application expects seconds but receives milliseconds, the resulting date can be completely wrong.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Local time vs UTC
&lt;/h3&gt;

&lt;p&gt;Unix timestamps represent an instant in time, while the human-readable representation can be displayed in different time zones.&lt;/p&gt;

&lt;p&gt;When debugging APIs, logs or databases, check which timezone the application expects.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Treating a timestamp as a formatted date
&lt;/h3&gt;

&lt;p&gt;A timestamp such as 1757894400 is not inherently a date string like 2025-09-15. It is a numeric representation of an instant in time.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Forgetting the unit
&lt;/h3&gt;

&lt;p&gt;Always document whether a field contains seconds, milliseconds or another unit.&lt;/p&gt;

&lt;p&gt;A quick way to convert Unix timestamps&lt;/p&gt;

&lt;p&gt;When debugging an API response or checking a log, you don't always want to write a script just to convert one timestamp.&lt;/p&gt;

&lt;p&gt;For quick conversions, you can use Devnary's browser-based Unix Timestamp Converter:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://devnary.in/tools/timestamp-converter" rel="noopener noreferrer"&gt;https://devnary.in/tools/timestamp-converter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is useful when you need to convert Unix timestamps to readable dates or convert dates back to Unix time without installing another application.&lt;/p&gt;

&lt;p&gt;For occasional debugging tasks, a small browser utility can be faster than opening a full development environment.&lt;/p&gt;

&lt;p&gt;Unix timestamp cheat sheet&lt;/p&gt;

&lt;p&gt;Unix epoch:&lt;br&gt;
January 1, 1970 00:00:00 UTC&lt;/p&gt;

&lt;p&gt;JavaScript milliseconds:&lt;br&gt;
Date.now()&lt;/p&gt;

&lt;p&gt;JavaScript seconds:&lt;br&gt;
Math.floor(Date.now() / 1000)&lt;/p&gt;

&lt;p&gt;Linux current timestamp:&lt;br&gt;
date +%s&lt;/p&gt;

&lt;p&gt;Python current timestamp:&lt;br&gt;
int(time.time())&lt;/p&gt;

&lt;p&gt;Important:&lt;br&gt;
Seconds and milliseconds are different units. Always check the API or system documentation before converting.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>coding</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
