| Crates.io | smart_date_time |
| lib.rs | smart_date_time |
| version | 0.1.2 |
| created_at | 2025-10-01 06:30:11.837427+00 |
| updated_at | 2025-10-01 12:49:29.450021+00 |
| description | A smart date time parser and formatter for rust |
| homepage | https://gitcode.net/dnrops/smart_date_time |
| repository | https://gitcode.net/dnrops/smart_date_time |
| max_upload_size | |
| id | 1862195 |
| size | 36,360 |
A smart date-time parsing and formatting Rust library that supports multiple date-time formats and languages, including Chinese, English, and other popular world languages.
2025-01-20 - Standard date format2025/1/20 - Slash-separated format2025.1.20 - Dot-separated format2025年1月20 - Chinese year-month format2025年1月20日 - Chinese complete date format01-01 - Month-day format (uses current year)1.2 - Dot-separated month-day format11.20 - Dot-separated month-day format20号 - Chinese date format13:42:52 - Complete time format13:42 - Hour-minute format13点 - Chinese hour format13点半 - Chinese half-hour format今天 - Current date (Chinese)doday - Current date (English)now - Current date-time (English)Add dependency to your Cargo.toml:
[dependencies]
smart_date_time = "0.1.0"
use smart_date_time;
// Parse and format date
let result = smart_date_time::format("2025-01-20", "YYYY-MM-DD");
println!("{}", result); // Output: 2025-01-20
// Parse Chinese format
let result = smart_date_time::format("今天", "YYYY年MM月DD日");
println!("{}", result); // Output: 2025年10月01日 (based on current date)
// Parse time format
let result = smart_date_time::format("13点半", "YYYY-MM-DD HH:mm");
println!("{}", result); // Output: 2025-10-01 13:30 (uses current date)
Supported formatting placeholders:
YYYY - Four-digit year (e.g., 2025)MM - Two-digit month (e.g., 01, 12)DD - Two-digit day (e.g., 01, 31)HH - Two-digit hour (24-hour format, e.g., 00, 23)mm - Two-digit minute (e.g., 00, 59)ss - Two-digit second (e.g., 00, 59)use smart_date_time;
// Various format examples
let examples = vec![
("2025-01-20", "YYYY-MM-DD"),
("2025/1/20", "YYYY/MM/DD"),
("2025.1.20", "YYYY.MM.DD"),
("2025年1月20日", "YYYY年MM月DD日"),
("01-01", "MM-DD"),
("20号", "DD号"),
("13:42:52", "HH:mm:ss"),
("13点半", "HH:mm"),
("今天", "今天是YYYY年MM月DD日"),
("now", "Current time: YYYY-MM-DD HH:mm:ss"),
];
for (input, format_str) in examples {
let result = smart_date_time::format(input, format_str);
println!("Input: {}, Format: {}, Result: {}", input, format_str, result);
}
chrono - Date-time handlingregex - Regular expression matchingRun tests:
cargo test
Run examples:
cargo run
We welcome contributions! If you'd like to help implement support for additional languages or improve existing functionality, please:
Issues and Pull Requests are welcome!
This project is licensed under the MIT License. See the LICENSE file for details.