Skip to content

Commit 1c5bf24

Browse files
committed
std/time: Give an example to get UNIX_EPOCH in seconds
1 parent 088216f commit 1c5bf24

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libstd/time/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,17 @@ impl fmt::Debug for SystemTime {
382382
/// [`SystemTime`] instance to represent another fixed point in time.
383383
///
384384
/// [`SystemTime`]: ../../std/time/struct.SystemTime.html
385+
///
386+
/// # Examples
387+
///
388+
/// ```no_run
389+
/// use std::time::{SystemTime, UNIX_EPOCH};
390+
///
391+
/// match SystemTime::now().duration_since(UNIX_EPOCH) {
392+
/// Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
393+
/// Err(_) => panic!("SystemTime before UNIX EPOCH!"),
394+
/// }
395+
/// ```
385396
#[stable(feature = "time2", since = "1.8.0")]
386397
pub const UNIX_EPOCH: SystemTime = SystemTime(time::UNIX_EPOCH);
387398

0 commit comments

Comments
 (0)