Skip to content

Commit fdb8d0b

Browse files
Rollup merge of rust-lang#44315 - kallisti5:epoch-doc-example-squashed, r=GuillaumeGomez
std/time: Give an example to get UNIX_EPOCH in seconds
2 parents 50f14e9 + 1c5bf24 commit fdb8d0b

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)