Rust
Rust
How to Parse a TimeStamp (such as 2016-11-11T14:32:17.0908971Z)
Timestamps are frequently used in REST API responses. This example demonstrates how to parse a timestamp string to get at the date/time components in the local timezone or in the GMT/UTC timezone.Chilkat Rust Downloads
// Let's say we have a timestamp string such as 2016-11-11T14:32:17.0908971Z
let str_timestamp = "2016-11-11T14:32:17.0908971Z".to_string();
let date_time = chilkat::DateTime::new();
let _ = date_time.set_from_timestamp(&str_timestamp);
// Get a DtObj in the local timezone.
let mut b_local_timezone = true;
let dt = chilkat::DtObj::new();
date_time.to_dt_obj(b_local_timezone, &dt);
// Get the individual date/time components
println!("-- Local Time --");
println!("Year: {}", dt.year());
println!("Month: {}", dt.month());
println!("Day: {}", dt.day());
println!("Hour: {}", dt.hour());
println!("Minutes: {}", dt.minute());
println!("Seconds: {}", dt.second());
// Get a DtObj in the GMT/UTC timezone.
b_local_timezone = false;
date_time.to_dt_obj(b_local_timezone, &dt);
// Get the individual date/time components
println!("-- UTC Time --");
println!("Year: {}", dt.year());
println!("Month: {}", dt.month());
println!("Day: {}", dt.day());
println!("Hour: {}", dt.hour());
println!("Minutes: {}", dt.minute());
println!("Seconds: {}", dt.second());