Xbase++ Requires Chilkat v11.0.0+
Xbase++
Get Email Date/Time
Demonstrates getting the email "Date" header field in a CkDateTime object.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oEmail
LOCAL oDtTime
LOCAL nBLocalTime
LOCAL nUnixTime
LOCAL oDtObj
nSuccess := 0
oEmail := CreateObject("Chilkat.Email")
// Load a .eml file into the email object.
nSuccess := oEmail:LoadEml("/home/users/chilkat/eml/myEml.eml")
oDtTime := CreateObject("Chilkat.CkDateTime")
oDtTime:SetFromRfc822(oEmail:EmailDateStr)
// Once we have the CkDateTime object, we can get the date/time in many different formats:
// Get as a RFC822 GMT string:
nBLocalTime := 0
? oDtTime:GetAsRfc822(nBLocalTime)
// Get as an RFC822 string in the local timezone.
// (remember, the daylight savings that existed at the given time in the past is applied)
nBLocalTime := 1
? oDtTime:GetAsRfc822(nBLocalTime)
// 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).
nUnixTime := oDtTime:GetAsUnixTime(nBLocalTime)
? "Unix time: " + Str(nUnixTime)
// 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:
oDtObj := CreateObject("Chilkat.DtObj")
oDtTime:ToDtObj(nBLocalTime, oDtObj)
IF (oDtTime:LastMethodSuccess == 0)
? "This should never really happen!"
oEmail:destroy()
oDtTime:destroy()
oDtObj:destroy()
RETURN
ENDIF
? Str(oDtObj:Day) + "-" + Str(oDtObj:Month) + "-" + Str(oDtObj:Year) + " " + Str(oDtObj:Hour) + ":" + Str(oDtObj:Minute) + ":" + Str(oDtObj:Second)
oEmail:destroy()
oDtTime:destroy()
oDtObj:destroy()