How to get the current date and time with milliseconds accuracy in Rust

2 Answers

0 votes
use chrono::Utc;

fn main() {
    let now = Utc::now();
    
    println!("{}", now.to_rfc3339());
}


   
/*
run:
  
2024-12-06T15:43:36.398171783+00:00
  
*/

 



answered Dec 6, 2024 by avibootz
0 votes
use chrono::Utc;

fn main() {
    let datetime = Utc::now().format("%Y-%m-%d %H:%M:%S.%f").to_string();
    
    print!("{}", datetime);
}


   
/*
run:
  
2024-12-06 15:44:47.646385938
  
*/

 



answered Dec 6, 2024 by avibootz
...