Rust Requires Chilkat v11.0.0+
Rust
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 Rust Downloads
// Parse Microsoft JSON Dates (AJAX Dates)
let json = chilkat::JsonObject::new();
let _ = json.load("{ \"AchievementDate\":\"/Date(1540229468330-0500)/\"}").is_ok();
let dt = chilkat::DateTime::new();
if json.date_of("AchievementDate", &dt).is_err() {
println!("Unable to parse a date/time.");
return;
}
// Show the date in different formats:
let b_local = true;
println!("RFC822: {}", dt.get_as_rfc822(b_local).unwrap_or_default());
println!("Timestamp: {}", dt.get_as_timestamp(b_local).unwrap_or_default());
println!("YYYY-MM-DD: {}", dt.get_as_iso8601("YYYY-MM-DD", b_local).unwrap_or_default());
// Get integer values for year, month, day, etc.
let dt_obj = chilkat::DtObj::new();
dt.to_dt_obj(b_local, &dt_obj);
println!("year: {}", dt_obj.year());
println!("month: {}", dt_obj.month());
println!("day: {}", dt_obj.day());
println!("hour: {}", dt_obj.hour());
println!("minute: {}", dt_obj.minute());
println!("seconds: {}", dt_obj.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