Rust Requires Chilkat v11.0.0+
Rust
Get Email Date/Time
Demonstrates getting the email "Date" header field in a CkDateTime object.Chilkat Rust Downloads
let email = chilkat::Email::new();
// Load a .eml file into the email object.
let _ = email.load_eml("/home/users/chilkat/eml/myEml.eml").is_ok();
let dt_time = chilkat::DateTime::new();
let _ = dt_time.set_from_rfc822(&email.email_date_str());
// Once we have the CkDateTime object, we can get the date/time in many different formats:
// Get as a RFC822 GMT string:
let mut b_local_time = false;
println!("{}", dt_time.get_as_rfc822(b_local_time).unwrap_or_default());
// Get as an RFC822 string in the local timezone.
// (remember, the daylight savings that existed at the given time in the past is applied)
b_local_time = true;
println!("{}", dt_time.get_as_rfc822(b_local_time).unwrap_or_default());
// Get as a 32-bit UNIX time (local or GMT..)
// The Unix time is number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
let unix_time = dt_time.get_as_unix_time(b_local_time) as i32;
println!("Unix time: {}", unix_time);
// One can also get the as a "DtObj" object for accessing the individual
// parts of the date/time, such as month, day, year, hour, minute, etc.
// The DtObj can be obtained in the GMT or local timezone:
let dt_obj = chilkat::DtObj::new();
dt_time.to_dt_obj(b_local_time, &dt_obj);
if !dt_time.last_method_success() {
println!("This should never really happen!");
return;
}
println!("{}-{}-{} {}:{}:{}", dt_obj.day(), dt_obj.month(), dt_obj.year(), dt_obj.hour(), dt_obj.minute(), dt_obj.second());