Search code examples
datetimerustepoch

convert u32 to SystemTime


In rust, how can I convert a u32 Unix Epoch based value into a std::time::SystemTime ?

In my case, the u32 value is from a gzip header modified time.



Converse question: How can I convert SystemTime::now() to an integer type?.


Solution

  • Add a Duration to SystemTime::UNIX_EPOCH:

    let time = SystemTime::UNIX_EPOCH + Duration::from_secs(value);