Module twilight_model::util::datetime

source ·
Expand description

Utilities for parsing and formatting ISO 8601 timestamps.

§Examples

Parse an acceptable ISO 8601 timestamp into a Timestamp:

use std::str::FromStr;
use twilight_model::util::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::util::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(),
);

Structs§

Enums§