]> git.lizzy.rs Git - rust.git/commitdiff
std/time: Give an example to get UNIX_EPOCH in seconds
authorAlexander von Gluck IV <kallisti5@unixzen.com>
Mon, 4 Sep 2017 16:08:08 +0000 (11:08 -0500)
committerAlexander von Gluck IV <kallisti5@unixzen.com>
Tue, 5 Sep 2017 00:21:58 +0000 (19:21 -0500)
src/libstd/time/mod.rs

index 5b893505b34d2aac1a14488de4d6e45d0f3186d1..e0dd8cfe62e6fe2291c80d3e7a4d6a61724490e8 100644 (file)
@@ -382,6 +382,17 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 /// [`SystemTime`] instance to represent another fixed point in time.
 ///
 /// [`SystemTime`]: ../../std/time/struct.SystemTime.html
+///
+/// # Examples
+///
+/// ```no_run
+/// use std::time::{SystemTime, UNIX_EPOCH};
+///
+/// match SystemTime::now().duration_since(UNIX_EPOCH) {
+///     Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
+///     Err(_) => panic!("SystemTime before UNIX EPOCH!"),
+/// }
+/// ```
 #[stable(feature = "time2", since = "1.8.0")]
 pub const UNIX_EPOCH: SystemTime = SystemTime(time::UNIX_EPOCH);