Module twilight_model::datetime[][src]

Expand description

Utilities for parsing and format ISO 8601 timestamps returned by the API.

Examples

Parse an acceptable ISO 8601 timestamp into a Timestamp:

use std::str::FromStr;
use twilight_model::datetime::Timestamp;

let timestamp = Timestamp::from_str("2020-02-02T02:02:02.020000+00:00")?;

// Check the Unix timestamp, which includes microseconds.
assert_eq!(1_580_608_922_020_000, timestamp.as_micros());

Format a timestamp as an ISO 8601 string used by the Discord API:

use twilight_model::datetime::Timestamp;

let timestamp = Timestamp::from_secs(1_580_608_922)?;

assert_eq!(
    "2020-02-02T02:02:02.000000+00:00",
    timestamp.iso_8601().to_string(),
);

Re-exports

pub use self::error::TimestampParseError;

Modules

Error detail implementation for Timestamp parsing.

Structs

Representation of a Unix timestamp with milliseconds.

Display implementation to format a Timestamp in an ISO 8601 format.