Ruby Requires Chilkat v11.0.0+
Ruby
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.
Chilkat Ruby Downloads
require 'chilkat'
success = false
# Assumes Chilkat is unlocked. See Global Unlock Sample.
email = Chilkat::CkEmail.new()
success = email.LoadEml("message.eml")
if (success != true)
print email.lastErrorText() + "\n";
exit
end
dateHeader = email.getHeaderField("Date")
when = Chilkat::CkDateTime.new()
success = when.SetFromRfc822(dateHeader)
if (success != true)
print "Failed: when.SetFromRfc822." + "\n";
exit
end
print "Header: " + dateHeader + "\n";
print "UTC: " + when.getAsTimestamp(false) + "\n";
print "Local: " + when.getAsTimestamp(true) + "\n";