JavaScript Requires Chilkat v11.0.0+
JavaScript
Read the sender’s Date in UTC and local time
See more Email Object Examples
Parse the Date header from an EML file, then print the same instant in UTC and the current computer’s local zone. Date is the time reported by the sender. For a relay timestamp, use a Received header.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
var email = new CkEmail();
success = email.LoadEml("message.eml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
var dateHeader = email.GetHeaderField("Date");
var when = new CkDateTime();
success = when.SetFromRfc822(dateHeader);
if (success !== true) {
console.log("Failed: when.SetFromRfc822.");
return;
}
console.log("Header: " + dateHeader);
console.log("UTC: " + when.GetAsTimestamp(false));
console.log("Local: " + when.GetAsTimestamp(true));