Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.0.0+

Get Certificate Valid To/From Dates

Demonstrates how to get the certificate "valid from" and "valid to" dates.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local cert = chilkat.Cert.new()

local success = cert:load_from_file("qa_data/certs/testCert.cer")
if not success then
    print(cert.last_error_text)
    return
end

-- Get the certificate valid-from date/time
local ckdt = chilkat.DateTime.new()
ckdt:set_from_rfc822(cert.valid_from_str)

-- Get the local timestamp string.
print("Valid from: " .. ckdt:get_as_timestamp(true))
-- Valid from: 2017-03-17T19:00:00-05:00

-- Now get the date/time as another object where we can get the individual numeric date parts.
local dt = chilkat.DtObj.new()
ckdt:to_dt_obj(true, dt)

print(dt.day .. "/" .. dt.month .. "/" .. dt.year .. "  " .. dt.hour .. ":" .. dt.minute)

-- Get the certificate valid-to date/time
ckdt:set_from_rfc822(cert.valid_to_str)

print("Valid to: " .. ckdt:get_as_timestamp(true))
-- Valid to: 2020-03-18T18:59:59-05:00new DtObj dt;
ckdt:to_dt_obj(true, dt)

print(dt.day .. "/" .. dt.month .. "/" .. dt.year .. "  " .. dt.hour .. ":" .. dt.minute)