Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Timestamp of the current Date and time in Rust

Tags:

I simply want to retrieve the current Time and Date and store it in a variable. For this I tried to use the chrono::DateTime.

In the documentation I found this:

use chrono::{DateTime, TimeZone, NaiveDateTime, Utc};  let dt = DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2016, 7, 8).and_hms(9, 10, 11), Utc);     

This lets me store a specific Date and Time but I couldnt figure how to retrieve the actual current date and time and put it in my DateTime-Variable.

like image 769
Samuel Dressel Avatar asked Aug 29 '19 10:08

Samuel Dressel


People also ask

How do I get the current date and time in rust?

You can get the current date and time in the UTC time zone ( Utc::now() ) or in the local time zone ( Local::now() ). Alternatively, you can create your own date and time.


1 Answers

Use rust, use it now:

use chrono;  fn main() {     println!("{:?}", chrono::offset::Local::now());     println!("{:?}", chrono::offset::Utc::now()); } 
like image 92
edwardw Avatar answered Sep 22 '22 19:09

edwardw