Date & Time Format Cheatsheet - Date Formatting & Timestamp Reference

Date bugs are usually timezone bugs — a timestamp that looks right locally is off by 8 hours elsewhere. Organized by strftime tokens, ISO 8601, timezones/offsets, per-language methods and timestamp conversion, this table lets you map a token to its output and avoid the classic UTC vs local pitfall. Use it when formatting logs, building API timestamps, or parsing ISO strings. After reading you pick a format that round-trips consistently across servers and clients.

Reference·50 commands·Last updated 2026-07-21
datetimeTimeFormatsstrftime

strftime Format Specifiers 13

%Y
四位年份(2024)
%y
两位年份(24)
%m
月份(01-12)
%d
日期(01-31)
%H
小时 24 小时制(00-23)
%I
小时 12 小时制(01-12)
%M
分钟(00-59)
%S
秒(00-59)
%p
AM/PM 标记
%A
星期全名(Monday)
%B
月份全名(January)
%Z
时区名称(UTC/CST)
%s
Unix 时间戳(秒)

ISO 8601 Standard 7

2024-01-15
日期格式(YYYY-MM-DD)
2024-01-15T10:30:00Z
UTC 时间(Z 表示零偏移)
2024-01-15T10:30:00+08:00
带时区偏移
2024-01-15T10:30:00.123Z
带毫秒精度
2024-W03-1
ISO 周日期(第 3 周周一)
2024-015
ISO 序数日(当年第 15 天)
PT1H30M
持续时间(1 小时 30 分)

Timezone & Offset 6

UTC
协调世界时(基准时区)
GMT
格林威治标准时间(同 UTC)
+08:00
东八区偏移(北京时间)
Asia/Shanghai
IANA 时区标识
America/New_York
IANA 时区(含夏令时)
DST
夏令时(Daylight Saving Time)

Date Formatting by Language 7

new Date().toISOString()
JavaScript ISO 格式
datetime.now().strftime("%Y-%m-%d")
Python strftime 格式化
date("+%Y-%m-%d %H:%M:%S")
Shell date 命令
SimpleDateFormat("yyyy-MM-dd")
Java 格式化(yyyy=年 MM=月)
time.Now().Format("2006-01-02")
Go 格式化(参考时间)
chrono::Local::now()
Rust chrono 库Get本地时间
Intl.DateTimeFormat().format()
JS 国际化日期格式化

Timestamp Conversion 6

Date.now()
JS Get毫秒时间戳(13 位)
int(time.time())
Python Get秒级时间戳
date +%s
Shell Get时间戳
new Date(1705312200 * 1000)
JS 时间戳转日期object
datetime.fromtimestamp(1705312200)
Python 时间戳转日期
date -d @1705312200
Shell 时间戳转可读日期

Date Arithmetic 6

now + timedelta(days=7)
Python 日期加 7 天
new Date(Date.now() + 86400000)
JS 日期加 1 天(毫秒)
date -d "+1 days"
Shell 日期加 1 天
d1 > d2
日期compare(先转同一type)
(d2 - d1).days
Python 计算日期差值(天数)
dayjs(d1).isAfter(d2)
JS dayjs 日期compare

Common Date Formats 5

2024-01-15 10:30:00
SQL/MySQL 默认格式
Mon, 15 Jan 2024 10:30:00 GMT
RFC 2822(邮件/HTTP 头)
2024/01/15
常见斜杠分隔格式
20240115
紧凑日期格式(YYYYMMDD)
1705312200
Unix 时间戳(秒)

Tips

  • ISO 8601 is the international standard — use it consistently in APIs and databases.
  • Go's reference time is 2006-01-02 15:04:05 (Mon Jan 2 15:04:05 MST 2006).
  • Unix timestamp is seconds (10 digits); JavaScript Date.now() is milliseconds (13 digits).
  • For timezones, store in UTC and convert to local only when displaying.
  • Java's SimpleDateFormat is not thread-safe; use DateTimeFormatter in multithreaded code.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us