px普贤教程PuXian
普贤教程 › 包参考

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_yeary
dt_days_in_monthy, m
dt_quartery, m
dt_week_of_yeary, m, d
dt_comparea_sec, b_sec
dt_duration_parses
dt_duration_formatsec
dt_to_timezonesec, off_sec
dt_date_onlysec
dt_time_onlysec
dt_yearsec
dt_monthsec
dt_daysec
dt_hoursec
dt_minutesec
dt_secondsec
其余 36 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
dt_now
dt_now_sec
dt_parses, fmt = DT_FMT
dt_formatsec, fmt = DT_FMT
dt_addsec, delta_sec
dt_diffa_sec, b_sec
dt_add_dayssec, n
dt_days_betweena_sec, b_sec
dt_weekdayy, m, d
dt_iso_parses
dt_iso_formatsec
dt_humanenow_sec, then_sec
du_is_leap_yearyear
du_days_in_monthyear, month
du_componentsts
du_replacetext, old, new
du_pad2n
du_pad4n
du_formatts, fmt
du_now
du_to_rfc822ts
du_to_iso8601ts
du_to_timestampyear, month, day, hour, minute, second
du_from_iso8601s
du_add_secondsts, n
du_add_minutests, n
du_add_hoursts, n
du_add_daysts, n
du_diffts1, ts2
du_diff_daysts1, ts2
du_day_of_weekyear, month, day
du_day_of_yearyear, month, day
du_week_of_yearyear, month, day
du_to_julianyear, month, day
du_from_julianjd
du_relative_timets

包内说明(源码头注释)

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)
============================================================