Tcl
Tcl
Get Email Date/Time
Demonstrates getting the email "Date" header field in a CkDateTime object.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
set email [new_CkEmail]
# Load a .eml file into the email object.
set success [CkEmail_LoadEml $email "/home/users/chilkat/eml/myEml.eml"]
set dtTime [new_CkDateTime]
CkDateTime_SetFromRfc822 $dtTime [CkEmail_emailDateStr $email]
# Once we have the CkDateTime object, we can get the date/time in many different formats:
# Get as a RFC822 GMT string:
set bLocalTime 0
puts [CkDateTime_getAsRfc822 $dtTime $bLocalTime]
# Get as an RFC822 string in the local timezone.
# (remember, the daylight savings that existed at the given time in the past is applied)
set bLocalTime 1
puts [CkDateTime_getAsRfc822 $dtTime $bLocalTime]
# 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).
set unixTime [CkDateTime_GetAsUnixTime $dtTime $bLocalTime]
puts "Unix time: $unixTime"
# 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:
set dtObj [new_CkDtObj]
CkDateTime_ToDtObj $dtTime $bLocalTime $dtObj
if {[CkDateTime_get_LastMethodSuccess $dtTime] == 0} then {
puts "This should never really happen!"
delete_CkEmail $email
delete_CkDateTime $dtTime
delete_CkDtObj $dtObj
exit
}
puts [CkDtObj_get_Day $dtObj]-[CkDtObj_get_Month $dtObj]-[CkDtObj_get_Year $dtObj] [CkDtObj_get_Hour $dtObj]:[CkDtObj_get_Minute $dtObj]:[CkDtObj_get_Second $dtObj]
delete_CkEmail $email
delete_CkDateTime $dtTime
delete_CkDtObj $dtObj