daily pastebin goal
81%
SHARE
TWEET

Untitled

a guest Jul 13th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern crate chrono; // 0.4.4
  2.  
  3.  
  4. use std::time::{
  5.     Duration,
  6.     SystemTime,
  7.     UNIX_EPOCH,
  8. };
  9.  
  10. use chrono::{
  11.     DateTime,
  12.     Utc,
  13. };
  14.  
  15. fn format_iso8601(ts: SystemTime) -> String {
  16.     let fmt = DateTime::<Utc>::from(ts).format("%Y-%m-%dT%H:%M:%S%.6fZ");
  17.     format!("{}", fmt)
  18. }
  19.  
  20. fn main() {
  21.     println!("{}", format_iso8601(UNIX_EPOCH));
  22.     println!("{}", format_iso8601(SystemTime::now()));
  23.     println!("{}", format_iso8601(UNIX_EPOCH + Duration::new(8474622245848, 0)));
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top