Guest User

Untitled

a guest
Jul 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment