Date & Time Format Cheatsheet - Date Formatting & Timestamp Reference

All essential Date & Time Format commands organized by use case, with 50+ entries you can copy and run directly. Find the right command fast when you need it.

Reference·50 commands·Last updated 2026-07-21
Back to Reference

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 是国际标准格式,推荐在 API 和数据库中统一使用。
  • Go 的参考时间是 2006-01-02 15:04:05(Mon Jan 2 15:04:05 MST 2006)。
  • Unix 时间戳是秒数(10 位),JavaScript 的 Date.now() 是毫秒数(13 位)。
  • 处理时区问题时,建议统一用 UTC 存储,显示时再转换为本地时区。
  • Java 的 SimpleDateFormat 线程不安全,多线程环境推荐用 DateTimeFormatter。

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

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