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

Parse a Microsoft JSON Date (MS AJAX Date)

See more JSON Examples

Demonstrates how to parse a Microsoft JSON Date, also known as an MSAJAX date.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Parse Microsoft JSON Dates (AJAX Dates)
local json = chilkat.JsonObject.new()

local success = json:load("{ \"AchievementDate\":\"/Date(1540229468330-0500)/\"}")

local dt = chilkat.DateTime.new()
success = json:date_of("AchievementDate", dt)
if not success then
    print("Unable to parse a date/time.")
    return
end

-- Show the date in different formats:
local bLocal = true
print("RFC822: " .. dt:get_as_rfc822(bLocal))
print("Timestamp: " .. dt:get_as_timestamp(bLocal))
print("YYYY-MM-DD: " .. dt:get_as_iso8601("YYYY-MM-DD", bLocal))

-- Get integer values for year, month, day, etc.
local dtObj = chilkat.DtObj.new()
dt:to_dt_obj(bLocal, dtObj)

print("year: " .. dtObj.year)
print("month: " .. dtObj.month)
print("day: " .. dtObj.day)
print("hour: " .. dtObj.hour)
print("minute: " .. dtObj.minute)
print("seconds: " .. dtObj.second)

-- Sample output:
-- RFC822: Mon, 22 Oct 2018 17:31:08 -0500
-- Timestamp: 2018-10-22T17:31:08-05:00
-- YYYY-MM-DD: 2018-10-22
-- year: 2018
-- month: 10
-- day: 22
-- hour: 17
-- minute: 31
-- seconds: 8