Sample code for 30+ languages & platforms
Rust

Extract Timestamp from ULID

See more ULID/UUID Examples

Extract the date/time from a ULID.

Important: Chilkat's ULID functionality was introduced in v9.5.0.94.

Chilkat Rust Downloads

Rust

let ulid = "01GRH14AA82EY9A7S99YYF2QDY".to_string();

let dt = chilkat::DateTime::new();

// Unix timestamps stored in ULIDs should be UTC...
let b_local = false;
// Set the CkDateTime from the timestamp contained in the ULID
if dt.set_from_ulid(b_local, &ulid).is_err() {
    println!("ULID was not valid.");
    return;
}

// You can now get the date/time in any desired format.
// For example:
println!("Unix timestamp = {}", dt.get_as_unix_time(b_local));
println!("RFC822 = {}", dt.get_as_rfc822(b_local).unwrap_or_default());
println!("Timestamp = {}", dt.get_as_timestamp(b_local).unwrap_or_default());

// Sample output:

// Unix timestamp = 1675608861
// RFC822 = Sun, 05 Feb 2023 14:54:21 GMT
// Timestamp = 2023-02-05T14:54:21Z