Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const ulid = "01GRH14AA82EY9A7S99YYF2QDY";
const dt = try chilkat.DateTime.init();
defer dt.deinit();
// Unix timestamps stored in ULIDs should be UTC...
const b_local = false;
// Set the CkDateTime from the timestamp contained in the ULID
dt.setFromUlid(b_local, ulid) catch {
std.debug.print("ULID was not valid.\n", .{});
return;
};
// You can now get the date/time in any desired format.
// For example:
std.debug.print("Unix timestamp = {d}\n", .{dt.getAsUnixTime(b_local)});
std.debug.print("RFC822 = {s}\n", .{try dt.getAsRfc822(alloc, b_local)});
std.debug.print("Timestamp = {s}\n", .{try dt.getAsTimestamp(alloc, b_local)});
// Sample output:
// Unix timestamp = 1675608861
// RFC822 = Sun, 05 Feb 2023 14:54:21 GMT
// Timestamp = 2023-02-05T14:54:21Z
}