Date.format
Date.format
功能
按 chrono/strftime 风格格式字符串输出日期时间。
语法
date_value.format(pattern)
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| pattern | String | 否 | %Y-%m-%d %H:%M:%S | 格式字符串。 |
返回值
| 类型 | 说明 |
|---|---|
| String | 返回格式化后的日期字符串。 |
代码示例
d = date('2026-06-09 10:11:12') result = d.format('%Y-%m-%d') // 输出:2026-06-09
注意事项
- 格式符使用 chrono/strftime 风格,例如
%Y-%m-%d %H:%M:%S、%F %T。 - 不传 pattern 时返回
%Y-%m-%d %H:%M:%S格式。