Sample code for 30+ languages & platforms
Lua Requires Chilkat v9.5.0.94+

Extract Timestamp from ULID

See more ULID/UUID Examples

Extract the date/time from a ULID.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local ulid = "01GRH14AA82EY9A7S99YYF2QDY"

local dt = chilkat.DateTime.new()

-- Unix timestamps stored in ULIDs should be UTC...
local bLocal = false
-- Set the CkDateTime from the timestamp contained in the ULID
local success = dt:set_from_ulid(bLocal, ulid)
if not success then
    print("ULID was not valid.")
    return
end

-- You can now get the date/time in any desired format.
-- For example:
print("Unix timestamp = " .. dt:get_as_unix_time(bLocal))
print("RFC822 = " .. dt:get_as_rfc822(bLocal))
print("Timestamp = " .. dt:get_as_timestamp(bLocal))

-- Sample output:

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