2 个版本 (1 个稳定版)
| 1.0.0 | 2024年4月29日 |
|---|---|
| 0.0.0 | 2024年4月26日 |
#60 在 日期和时间
52KB
1.5K SLoC
timezone (tz) - 英文语言时区转换
目录
安装
从源码构建
源代码可以在这个 GitHub 仓库中找到。获取源代码后,编译的最简单方法是使用 cargo build --release,然后将 path/to/timezone/target/release 添加到您的 PATH。我不知道这个软件是否能在 Windows 上编译,如果您遇到任何问题,请 提交一个问题。
crates.io
此软件还可在 crates.io 上分发,应能够使用 cargo install timezone 安装。
使用
作为库
您可以使用 cargo add timezone 在其他 Rust 程序中使用此软件。实际的转换逻辑主要由 chrono-tz 处理,但 src/parse.rs 提供了几个解析英文语言输入的方法,这可能对您有帮助。
作为 CLI
tz time origin_timezone destination_timezone day month year
例如
tz 1pm et bst tomorrow
将告诉您明天夏令时美国东部时间下午1点在英国是什么时间。
参数
时间
time 应该是以下格式之一
| 格式 | 示例 |
|---|---|
| SimpleAmPm | 1am, 10pm |
| FullAmPm | 12:24am, 6:30pm |
| MilitaryColon | 07:00, 13:52 |
| Military | 0900, 1634 |
origin_timezone 和 destination_timezone
时区可以是城市,例如 Europe/London、America/Los_Angeles,甚至是 US/Eastern;或者时区缩写,例如 gmt、est、aet。完整的缩写列表可以在 src/convert_timezones.rs 中找到。
day、month 和 year
day、month 和 year 大部分是自解释的,但你也可以指定 today、tomorrow 或 yesterday 作为 day。
必需参数
此软件功能强大,您无需完全指定要执行的转换。至少您只需指定时间和起源,其余的将被假定为您的本地时区、当前日期、当前月份和当前年份。
依赖项
~4–16MB
~140K SLoC