Learn About Time

What is Unix Time?

Unix time, also known as POSIX time or epoch time, counts seconds since January 1, 1970 at 00:00:00 UTC (Coordinated Universal Time). This date is called the "Unix epoch."

It's widely used in computing for timestamps because it's a simple, continuously increasing number that's easy to compare, sort, and perform arithmetic operations on.

Example: Unix timestamp 1690646400 represents July 29, 2023 at 12:00:00 UTC.

The 2038 Problem

Systems using 32-bit signed integers to store Unix time will overflow on January 19, 2038 at 03:14:07 UTC, when the value exceeds 2^31−1 (2,147,483,647 seconds).

After this point, 32-bit systems will wrap around to negative numbers, potentially causing dates to appear as December 13, 1901. Modern 64-bit systems can handle dates until the year 292 billion!

Critical Date: January 19, 2038 at 03:14:07 UTC (2,147,483,647 seconds since epoch)

Daylight Saving Time (DST)

Daylight saving time shifts clocks forward by one hour during warmer months in many regions to extend evening daylight. This practice can cause complications in software:

  • Spring forward: 2:00 AM becomes 3:00 AM (one hour is skipped)
  • Fall back: 2:00 AM happens twice (one hour is repeated)
  • Different regions change on different dates

Always use timezone-aware libraries and store times in UTC when possible to avoid DST issues.

Working with Timezones

Timezones are regions with the same standard time. The world is divided into approximately 24 time zones, each typically 15 degrees of longitude apart.

JavaScript APIs

  • Intl.DateTimeFormat - Format dates in different timezones
  • Date.prototype.toLocaleString() - Locale-specific formatting
  • Temporal (upcoming) - Modern date/time API

Popular Libraries

  • date-fns-tz - Lightweight timezone support
  • luxon - Modern alternative to Moment.js
  • dayjs - Fast 2kB alternative

ISO 8601 Standard

ISO 8601 is the international standard for date and time representation. It provides unambiguous date/time formats that are machine-readable and sortable.

Common Formats:

  • Date: 2025-07-29
  • Date and Time: 2025-07-29T14:30:00
  • With Timezone: 2025-07-29T14:30:00Z (UTC)
  • With Offset: 2025-07-29T14:30:00+02:00

Time Precision & Accuracy

Precision Levels

  • Seconds: Standard Unix time
  • Milliseconds: JavaScript Date (1/1000 second)
  • Microseconds: High-precision systems (1/1,000,000 second)
  • Nanoseconds: Scientific applications (1/1,000,000,000 second)

Common Sources of Error

  • Network latency in distributed systems
  • Clock drift between machines
  • Leap seconds (rare UTC adjustments)
  • Timezone database updates

Best Practices for Developers

✅ Do This

  • Store timestamps in UTC in your database
  • Use timezone-aware libraries for calculations
  • Validate and sanitize time inputs
  • Consider leap years and DST transitions
  • Use ISO 8601 format for data exchange

❌ Avoid This

  • Storing local times without timezone info
  • Hardcoding timezone offsets
  • Ignoring DST transitions in calculations
  • Using string manipulation for date math
  • Assuming all days have 24 hours

Additional Resources

Specifications

  • RFC 3339 - Date and Time on the Internet
  • ISO 8601 - International Date/Time Standard
  • IANA Time Zone Database

Tools & Testing

  • Use this site's converters and calculators
  • Test edge cases like DST transitions
  • Validate with multiple timezone scenarios