Crates.io | pretty_date |
lib.rs | pretty_date |
version | 0.1.2 |
source | src |
created_at | 2023-01-03 18:52:12.104001 |
updated_at | 2023-01-04 07:24:16.609072 |
description | A rust library for the simple, friendly, human readable formatting of the chrono NaiveDateTime |
homepage | https://github.com/mbcltd/pretty_date |
repository | https://github.com/mbcltd/pretty_date |
max_upload_size | |
id | 750326 |
size | 23,875 |
A rust library for the simple, friendly, human readable formatting for the chrono NaiveDateTime, for example:
Just now
20:56 Today
5 September, 23:56
Add this to your Cargo.toml
:
[dependencies]
pretty_date = "0.1.2"
Basic default usage:
use chrono::NaiveDateTime;
use pretty_date::pretty_date_formatter::PrettyDateFormatter;
fn main() {
let date = NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S").unwrap();
println!("{}", date.format_pretty());
}
Advanced usage:
use chrono::NaiveDateTime;
use pretty_date::pretty_date_format::PrettyDateFormat;
use pretty_date::pretty_date_rule::PrettyDateRule;
fn main() {
let date = NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S").unwrap();
let date_format = PrettyDateFormat {
rules: vec![
PrettyDateRule::Today,
PrettyDateRule::ThisYear,
],
default_format: "%-e %B %Y, %H:%M",
};
println!("{}", date_format.format_pretty(&date));
}
Rand is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.