Files
simpledateformat/README.md
2025-01-11 11:47:23 +08:00

49 lines
1.1 KiB
Markdown

# simpledateformat
SimpleDateFormat.java style like date format
Usage:
```rust
let f = match fmt("yyyy-MM-dd HH:mm:ss z") {
Ok(f) => f, Err(err) => {
println!("Parse fmt error: {}", err);
return;
},
};
println!("Formated date: {}", f.format(&Local::now()));
```
Output:
```
Formated date: 2020-05-30 13:32:04 +08:00
```
| Format | Date |
|-----------------------|-----------------------------------------|
| yy-M-d'T'H:m:s a z | 25-1-11T11:46:19 AM +08:00 |
| yyyy-MM-dd'T'HH:mm:ss z | 2025-01-11T11:43:41 +08:00 |
| EEE MMM dd yyyy HH:mm:ss z | Sat Jan 11 2025 11:44:34 +08:00 |
| EEEE MMMM dd yyyy HH:mm:ss z | Saturday January 11 2025 11:44:57 +08:00 |
```rust
format_human(Duration::from_secs(2 * 24 * 60 * 60 + 1));
```
Output:
```
2days 0hour 0min 1s
```
More tests:
> https://git.hatter.ink/hatter/simpledateformat/src/branch/master/tests/lib_test.rs
Log
* Jun 23, 2020 - v0.1.1
* add `simpledateformat::new_with_out_err(&str)`
* add `impl TryFrom<&str> for SimpleDateFormat`