Answers for "how to get the current time in rust"

0

rust elapsed time

use std::time::{Duration, Instant};
use std::thread::sleep;

fn main() {
   let now = Instant::now();

   // we sleep for 2 seconds
   sleep(Duration::new(2, 0));
   // it prints '2'
   println!("{}", now.elapsed().as_secs());
}
Posted by: Guest on April-15-2021
0

rust get current date

use chrono;

fn main() {
    println!("{:?}", chrono::offset::Local::now());
    println!("{:?}", chrono::offset::Utc::now());
}
Posted by: Guest on October-15-2020

Code answers related to "how to get the current time in rust"

Browse Popular Code Answers by Language