diff options
| author | Mark Simulacrum <mark.simulacrum@gmail.com> | 2017-09-06 18:27:53 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-06 18:27:53 -0600 |
| commit | fdb8d0beb43c4513eeab0c3dedf00a29b5cd1ca6 (patch) | |
| tree | d527e8c50fed8a01b1913976073a7ac0ca4e310e | |
| parent | 50f14e906f8592cb4b8e55bd9437107c5f482657 (diff) | |
| parent | 1c5bf2468b7f0fe2aa63c6037c82521bff1dac17 (diff) | |
| download | rust-fdb8d0beb43c4513eeab0c3dedf00a29b5cd1ca6.tar.gz rust-fdb8d0beb43c4513eeab0c3dedf00a29b5cd1ca6.zip | |
Rollup merge of #44315 - kallisti5:epoch-doc-example-squashed, r=GuillaumeGomez
std/time: Give an example to get UNIX_EPOCH in seconds
| -rw-r--r-- | src/libstd/time/mod.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libstd/time/mod.rs b/src/libstd/time/mod.rs index 5b893505b34..e0dd8cfe62e 100644 --- a/src/libstd/time/mod.rs +++ b/src/libstd/time/mod.rs @@ -382,6 +382,17 @@ impl fmt::Debug for SystemTime { /// [`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); |
