4 个版本
0.1.4 | 2022年5月17日 |
---|---|
0.1.3 | 2022年5月17日 |
0.1.1 | 2022年5月17日 |
0.1.0 | 2022年5月17日 |
#444 在 日期和时间
31 每月下载量
用于 render-cli
9KB
130 行
relativetime
relativetime
为 std::time::Duration
和 chrono::Duration
提供了 trait,以便轻松显示可读的相对时间。
use relativetime::{RelativeTime, NegativeRelativeTime};
fn main() {
let d = std::time::Duration::from_secs(1);
assert_eq!(d.relative_time(), "in a few seconds");
assert_eq!(d.relative_time_in_past(), "a few seconds ago");
let d = chrono::Duration::from_secs(-1);
assert_eq!(d.relative_time(), "a few seconds ago");
let d = chrono::Duration::from_secs(1);
assert_eq!(d.relative_time(), "in a few seconds");
}
请参阅 docs
了解 API,以及 测试 了解更多示例用法。
贡献
欢迎贡献!
依赖
~39–320KB