Urgent.News

What's breaking now, across thousands of outlets.

Tech

Unix Timestamps Explained: Seconds, Milliseconds, and Time Zones

A Unix timestamp (also called epoch time or POSIX time) is the number of seconds that have passed since 00:00:00 UTC on 1 January 1970, a moment known as the Unix epoch. It's a single number that identifies the same instant everywhere on Earth, which is why databases, logs, and APIs love it. Seconds or milliseconds? Different systems count in different units, and mixing them up is the most common…

A Unix timestamp, also known as epoch time or POSIX time, is a single number representing the number of seconds that have passed since 00:00:00 UTC on 1 January 1970, known as the Unix epoch. This number is universally applicable, which is why it is favored by databases, logs, and APIs. However, different systems count time in varying units, and mixing them up can lead to common timestamp bugs.

A quick way to differentiate between seconds and milliseconds is by the length of the number: 10 digits (like 1700000000) typically represent seconds, while 13 digits (like 1700000000000) represent milliseconds. JavaScript's Date.now() and Java's System.currentTimeMillis() return the latter.

Passing the wrong unit can set your data to January 1970 or, conversely, many thousands of years into the future. When coding, remember to multiply the seconds value by 1000 before passing it to JavaScript's Date constructor. Python's datetime library also provides a fromtimestamp() method that takes an optional timezone argument.

A Unix timestamp, being an instant in time and not a calendar date, is time-zone agnostic. It's best practice to store and transmit timestamps in this format or as UTC ISO 8601 strings (like 2023-11-14T22:13:20Z), converting to a viewer's time zone only when displaying the data. Common mistakes include adding 86,400 seconds to assume the next day, storing local time without a time zone offset, and comparing seconds to milliseconds.

When dealing with timestamps, always use UTC internally and 64-bit integers or ISO 8601 strings for storage to avoid the Year 2038 problem, where signed 32-bit Unix time will overflow on 19 January 2038. Using UTC for all calculations and only converting to local time for display ensures accurate time representation across all systems.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

How to Make a WiFi QR Code (So Guests Never Ask for the Password)

Reading a long, random WiFi password aloud to every guest gets old quickly. A WiFi QR code solves it: point a phone camera at the code and the phone offers to join the network.

  • WiFi QR codes simplify connecting to networks without sharing passwords.
  • iPhones (iOS 11+) and many Android phones can scan these codes.
  • Use a browser-based generator, test, and print at readable size near router.

How to Check Color Contrast for Accessibility (WCAG Explained)

Low-contrast text is one of the most common accessibility failures on the web, and one of the easiest to fix. It affects people with low vision and color-vision differences, but also anyone reading a…

  • WCAG quantifies contrast via ratio measuring luminance between colors.
  • Level AA requires minimum 4.5:1 contrast ratio for normal text.
  • Non-text elements like input borders need a minimum 3:1 contrast.

How Strong Should a Password Be? Length vs. Complexity

Password strength is really a question of how many guesses an attacker would need. Every extra character multiplies that number, which is why length matters far more than swapping an a for an @.

  • Length of password exponentially increases possible guesses for attacker
  • Entropy measures password unpredictability in bits, doubles with each bit
  • Passphrases made of random words offer strong security and memorability

Base64 Is Not Encryption (And Other Common Misconceptions)

Base64 shows up everywhere: emails, data URLs, HTTP headers, JWTs. Because the output looks scrambled, it is often mistaken for encryption. It isn't.

  • Base64 is an encoding method, not encryption
  • It converts binary data to text format, reversible by anyone
  • Used for text-only channels, not providing secrecy

More from Saturday 26 September →