23 lines
991 B
Rust
23 lines
991 B
Rust
use chrono::prelude::*;
|
|
|
|
// https://crates.io/crates/chrono
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
println!("UTC time: {}", Utc::now());
|
|
println!("UTC time: {:?}", Utc::now());
|
|
println!("UTC time(RFC2822): {}", Utc::now().to_rfc2822());
|
|
println!("UTC time(RFC3339): {}", Utc::now().to_rfc3339());
|
|
println!("Local time: {}", Local::now());
|
|
println!("Local time: {:?}", Local::now());
|
|
println!("Local time(RFC2822): {}", Local::now().to_rfc2822());
|
|
println!("Local time(RFC3339): {}", Local::now().to_rfc3339());
|
|
|
|
println!("{}", "2020-01-01T12:00:00Z".parse::<DateTime<Utc>>()?);
|
|
println!("{}", "2020-01-01T12:00:00+08:00".parse::<DateTime<Local>>()?);
|
|
|
|
println!("Current timestamp(secs): {}", Utc::now().timestamp());
|
|
println!("Current timestamp(millis): {}", Utc::now().timestamp_millis());
|
|
println!("Current timestamp(nanos): {}", Utc::now().timestamp_nanos());
|
|
|
|
Ok(())
|
|
}
|