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.
Back to Referencestrftime 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)
%pAM/PM 标记
%A星期全名(Monday)
%B月份全名(January)
%Z时区名称(UTC/CST)
%sUnix 时间戳(秒)
ISO 8601 Standard 7
2024-01-15日期格式(YYYY-MM-DD)
2024-01-15T10:30:00ZUTC 时间(Z 表示零偏移)
2024-01-15T10:30:00+08:00带时区偏移
2024-01-15T10:30:00.123Z带毫秒精度
2024-W03-1ISO 周日期(第 3 周周一)
2024-015ISO 序数日(当年第 15 天)
PT1H30M持续时间(1 小时 30 分)
Timezone & Offset 6
UTC协调世界时(基准时区)
GMT格林威治标准时间(同 UTC)
+08:00东八区偏移(北京时间)
Asia/ShanghaiIANA 时区标识
America/New_YorkIANA 时区(含夏令时)
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 +%sShell Get时间戳
new Date(1705312200 * 1000)JS 时间戳转日期object
datetime.fromtimestamp(1705312200)Python 时间戳转日期
date -d @1705312200Shell 时间戳转可读日期
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).daysPython 计算日期差值(天数)
dayjs(d1).isAfter(d2)JS dayjs 日期compare
Common Date Formats 5
2024-01-15 10:30:00SQL/MySQL 默认格式
Mon, 15 Jan 2024 10:30:00 GMTRFC 2822(邮件/HTTP 头)
2024/01/15常见斜杠分隔格式
20240115紧凑日期格式(YYYYMMDD)
1705312200Unix 时间戳(秒)
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