ckeyes888 wrote:Curious if it's possible using AS to convert military time to standard time, e.g. 2330 to 11:30 pm?
I use military time for my sprinkler set time, easier to adjust adding or subtracting to, and I'd like to be able
to have reminders/announcements based on that time, but in the am/pm format.
Carl, the formula for Military Time is simple...
Here's some pseudo code:
If hour => 13:
#
# Time is 24 hr
new_hour = hour - 12
And vice versa.
There is nothing tricky about 24 hour time...
Here's code to convert to 24 hour. The reason I am showing it, is simply to illustrate that most of the code is there to decode the time string...
I wasn't able to find any 24 to 12 code, at least my google foo failed me... I know it's out there...
-- This assumes that the input is a 12-hour time string, that any separators in it are colons, and that it ends with either "am" or "pm".
on h12toh24(input, separator)
set t to words of text 1 thru -3 of input
if (text -2 thru -1 of input is "pm") then set item 1 of t to (item 1 of t) + 12
repeat 3 - (count t) times
set end of t to 0
end repeat
tell (1000000 + (item 1 of t) * 10000 + (item 2 of t) * 100 + (item 3 of t)) as text
return text 2 thru 3 & separator & text 4 thru 5 & separator & text 6 thru 7
end tell
end h12toh24