UTCTime
Mark Wieder
mwieder at ahsoftware.net
Thu Dec 7 12:39:03 EST 2006
All-
What I love about UTC time is the fact that it's not an acronym for
anything, but a compromise that explicitly *doesn't* stand for
anything, since the English and French twits in the ITC couldn't agree
on whether it should be CUT or TUC.
I recently had to convert local time to UTC time for an application,
so I wrote a little function to do this for me and thought I'd share
it in case someone else finds it useful. I needed the format line at
the end to convert the result to the form the app needed - ignore it
as necessary.
-------------------------------------------------
-- UTCTime
--
-- convert the local date/time to a UTC date/time
-- returning it as YYYYMMDD-HH:MM:SS
--
-- Usage:
-- put UTCTime() into serverTime
------------------------------------------------
FUNCTION UTCTime
local tDate
local tUTCOffset
local tLocalDate
-- convert the local date to a UTC date
put the internet date into tDate
-- the last word is the offset of the local time from UTC time
put the last word of tDate into tUTCOffset -- (offset as -0800)
convert tDate to dateItems
subtract trunc(tUTCOffset/ 100) from item 4 of tDate
-- recalculate the dateItems
convert tDate to dateItems
put format ("%4d%02d%02d-%02d:%02d:%02d", \
item 1 of tDate, item 2 of tDate, item 3 of tDate, \
item 4 of tDate, item 5 of tDate, item 6 of tDate) into tLocalDate
return tLocalDate
END UTCTime
--
-Mark Wieder
mwieder at ahsoftware.net
More information about the use-livecode
mailing list