mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #44315 - kallisti5:epoch-doc-example-squashed, r=GuillaumeGomez
std/time: Give an example to get UNIX_EPOCH in seconds
This commit is contained in:
commit
fdb8d0beb4
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user