Date & Time Formats Cheat Sheet
Date and time formats define how temporal data is represented, stored, exchanged, and displayed. Correct formatting is critical for interoperability, logging, APIs, databases, and internationalization.
Core Concepts
| Term | Meaning |
|---|---|
| Date | Calendar day (year, month, day) |
| Time | Clock time (hours, minutes, seconds) |
| DateTime | Combined date and time |
| Time Zone | Offset from UTC |
| Timestamp | Numeric representation of time |
ISO 8601 (Recommended Standard)
ISO 8601 is the most widely used and safest format for data exchange.
YYYY-MM-DD
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SSZ
YYYY-MM-DDTHH:MM:SS±HH:MM
Examples:
2025-12-30
2025-12-30T14:45:00
2025-12-30T14:45:00Z
2025-12-30T14:45:00+03:00
Date Formats (Common Variants)
| Format | Example | Region |
|---|---|---|
YYYY-MM-DD |
2025-12-30 | ISO / Global |
DD/MM/YYYY |
30/12/2025 | Europe |
MM/DD/YYYY |
12/30/2025 | US |
DD.MM.YYYY |
30.12.2025 | Europe |
YYYY/MM/DD |
2025/12/30 | Asia |
⚠️ Ambiguous formats like 03/04/2025 should be avoided.
Time Formats
| Format | Example | Description |
|---|---|---|
HH:MM |
14:45 | 24-hour |
HH:MM:SS |
14:45:30 | With seconds |
HH:MM:SS.sss |
14:45:30.123 | With milliseconds |
hh:mm A |
02:45 PM | 12-hour |
Time Zones & Offsets
| Representation | Meaning |
|---|---|
Z |
UTC |
+00:00 |
UTC offset |
+03:00 |
UTC+3 |
-05:00 |
UTC-5 |
Europe/Istanbul |
IANA time zone |
Example:
2025-12-30T14:45:00+03:00
Unix Timestamp
A Unix timestamp represents seconds since 1970-01-01 00:00:00 UTC.
1703957100
Characteristics: - Time zone independent - Ideal for storage & comparison - Not human-readable
Programming Language Formats
Python (strftime)
| Token | Meaning |
|---|---|
%Y |
Year |
%m |
Month |
%d |
Day |
%H |
Hour (24h) |
%M |
Minute |
%S |
Second |
dt.strftime("%Y-%m-%d %H:%M:%S")
JavaScript
new Date().toISOString()
2025-12-30T11:45:00.000Z
Java (DateTimeFormatter)
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
PHP
date("Y-m-d H:i:s");
Database Formats
| Database | Preferred Format |
|---|---|
| MySQL | DATETIME / TIMESTAMP |
| PostgreSQL | TIMESTAMP WITH TIME ZONE |
| SQLite | ISO 8601 text |
| MongoDB | ISODate (UTC) |
RFC Standards
| RFC | Usage |
|---|---|
| RFC 3339 | APIs, JSON |
| RFC 1123 | HTTP headers |
Example (HTTP):
Tue, 30 Dec 2025 11:45:00 GMT
Best Practices
- Use ISO 8601 for storage & APIs
- Always store timestamps in UTC
- Convert to local time only for display
- Include time zone or offset
- Avoid locale-dependent formats in data exchange
- Prefer numeric timestamps for comparisons
Common Pitfalls
- Mixing local time with UTC
- Ignoring daylight saving time
- Using ambiguous formats
- Storing dates as strings without standard
- Assuming server and client share time zone
Summary
- ISO 8601 is the safest default
- Unix timestamps are ideal for storage
- Always be explicit about time zones
- Formatting rules vary by language and context