timediff
timediff 是一个 Rust 工具库,用于打印可阅读的相对时间段,支持 i18n。它是 Day.js 的 Rust 实现,弥补了 Rust 生态中类似工具的缺失。
• Copy the embed code to showcase this product on your website
• Share on X to spread the word about this amazing tool
- 项目地址:https://github.com/lryong/timediff- 语言:Rust- 项目描述:前端同学基本都知道 Moment.js 和 Day.js,其中 Day.js 是 Moment.js 替代工具,被广泛应用在前端项目中。 timediff 是 Day.js 支持 i18n 的一个 Rust 实现,用于打印不同语言的时间段表达,易于用户理解, 配合 humantime 基本可以完成 Day.js 的所有功能。 timediff 时间段的计算也遵循 Day.js 的规则,它很好地弥补了这个场景下的工具缺失。- 代码使用样例:
rust use timediff::*; use timediff::TimeDiffError as Error; assert_eq!( TimeDiff::to_diff(String::from("-10s")) .locale(String::from("zh-CN")) .unwrap() .parse(), Ok(String::from("几秒前")) );