Added examples/doctests for how to get a datetime from an epoch and vice versa.
This commit is contained in:
parent
b3adf050f5
commit
7e2f2e0bea
14
src/lib.rs
14
src/lib.rs
|
@ -299,6 +299,20 @@
|
|||
//! [`DateTime.timestamp_subsec_nanos`](./struct.DateTime.html#method.timestamp_subsec_nanos)
|
||||
//! to get the number of additional number of nanoseconds.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use chrono::DateTime;
|
||||
//! use chrono::Utc;
|
||||
//! // We need the trait in scope to use Utc::timestamp().
|
||||
//! use chrono::TimeZone;
|
||||
//!
|
||||
//! // Construct a datetime from epoch:
|
||||
//! let dt = Utc.timestamp(1500000000, 0);
|
||||
//! assert_eq!(dt.to_rfc2822(), "Fri, 14 Jul 2017 02:40:00 +0000");
|
||||
//!
|
||||
//! // from a datetime:
|
||||
//! let dt = DateTime::parse_from_rfc2822("Fri, 14 Jul 2017 02:40:00 +0000").unwrap();
|
||||
//! assert_eq!(dt.timestamp(), 1500000000);
|
||||
//! ```
|
||||
//! ### Individual date
|
||||
//!
|
||||
//! Chrono also provides an individual date type ([**`Date`**](./struct.Date.html)).
|
||||
|
|
Loading…
Reference in New Issue