普贤教程 › 包参考
datetime 包
0.2.0 —— 时间运算(增强版)
| 项 | 值 |
|---|---|
| 包名 | datetime |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | datetime.px |
| 分类 | 时间与日历 |
| 文件数 / 行数 | 1 / 518 |
安装与引入
bash
pxpkg init # 首次 pxpkg add datetime@0.2.0 pxpkg install
px
import datetime所属分类教程:时间与日历
公开接口
| 函数 | 参数 |
|---|---|
dt_is_leap_year | y |
dt_days_in_month | y, m |
dt_quarter | y, m |
dt_week_of_year | y, m, d |
dt_compare | a_sec, b_sec |
dt_duration_parse | s |
dt_duration_format | sec |
dt_to_timezone | sec, off_sec |
dt_date_only | sec |
dt_time_only | sec |
dt_year | sec |
dt_month | sec |
dt_day | sec |
dt_hour | sec |
dt_minute | sec |
dt_second | sec |
其余 36 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
dt_now | |
dt_now_sec | |
dt_parse | s, fmt = DT_FMT |
dt_format | sec, fmt = DT_FMT |
dt_add | sec, delta_sec |
dt_diff | a_sec, b_sec |
dt_add_days | sec, n |
dt_days_between | a_sec, b_sec |
dt_weekday | y, m, d |
dt_iso_parse | s |
dt_iso_format | sec |
dt_humane | now_sec, then_sec |
du_is_leap_year | year |
du_days_in_month | year, month |
du_components | ts |
du_replace | text, old, new |
du_pad2 | n |
du_pad4 | n |
du_format | ts, fmt |
du_now | |
du_to_rfc822 | ts |
du_to_iso8601 | ts |
du_to_timestamp | year, month, day, hour, minute, second |
du_from_iso8601 | s |
du_add_seconds | ts, n |
du_add_minutes | ts, n |
du_add_hours | ts, n |
du_add_days | ts, n |
du_diff | ts1, ts2 |
du_diff_days | ts1, ts2 |
du_day_of_week | year, month, day |
du_day_of_year | year, month, day |
du_week_of_year | year, month, day |
du_to_julian | year, month, day |
du_from_julian | jd |
du_relative_time | ts |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/datetime 0.2.0 —— 时间运算(增强版) ------------------------------------------------------------ 纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。 对齐 Go time / Python datetime / Rust chrono 心智: 新增: dt_quarter(y, m) → 1..4 季度 dt_week_of_year(y, m, d) → 年中周数(ISO 8601 周历) dt_is_leap_year(y) → 闰年判断 dt_days_in_month(y, m) → 月内天数 dt_compare(a_sec, b_sec) → -1/0/1 dt_duration_parse(s) → Ok(秒数) | Err("1h30m" / "90s" / "2d" / "1:30:00") dt_duration_format(sec) → "1h30m15s" 紧凑格式 dt_to_timezone(sec, off_sec) → 指定时区偏移的格式化字符串 dt_date_only(sec) → "YYYY-MM-DD"(UTC) dt_time_only(sec) → "HH:MM:SS"(UTC) dt_year(sec) / dt_month(sec) / dt_day(sec) / dt_hour(sec) / dt_minute(sec) / dt_second(sec) ============================================================