How can I format a time to HHMM with AppleScript? Is it possible to get the hour and minute in 24 hour HHMM format so that 1:01 would be 0101

I figured out a way to do it for the month and year but can't find a way for the hour and minute.

Here is what I have so far.

set whichUrl to 0
set fileNames to "map"
set theStartDate to the date "Tuesday, June 21, 2016 at 00:00:00"
set theEndDate to theStartDate + (60 * 60 * 24 * 365) --1 year
set theDate to theStartDate

repeat until theDate = theEndDate
        set theURL to "http://site.com/map.php?iso="

        set {year:y, month:m, day:d} to (theDate)
        set theModDate to (y * 10000 + m * 100 + d) as string

        set theURL to theURL &amp; theModDate &amp; hours of theDate
        set theURL to theURL &amp; minutes of theDate

        tell application "Safari"
            activate
            set the URL of document 1 to theURL as text
            delay 2

        end tell
    set theDate to theDate + (600) --advance 10 minutes
    set whichUrl to whichUrl + 1
end repeat
Here's a script that takes the current time and makes it HHMM as you asked.

-- preserve the current text item delimiters so we can put them back
set oldDelims to AppleScript's text item delimiters

set right_now to current date
set the_time to time string of right_now -- something like "4:20:56 PM"
set am_pm to characters -2 thru -1 of the_time as string -- is it AM or PM

set AppleScript's text item delimiters to ":"
set the_hour to text item 1 of the_time as string -- in this example, "4"
set the_minute to text item 2 of the_time as string -- in this example, "20"

if (am_pm is "PM") then
    set the_hour to the_hour + 12
end if

if the_hour is "24" then
    set the_hour to "12"
end if
-- that could have been more graceful but it's nice and obvious this way

if (count of the_hour) is 1 then -- padding with a zero if necessary
    set the_hour to "0" &amp; the_hour
end if

if (count of the_minute) is 1 then -- padding with a zero if necessary
    set the_minute to "0" &amp; the_minute
end if

set AppleScript's text item delimiters to ""
set steves_string to the_hour &amp; the_minute as string -- putting the pieces together

set AppleScript's text item delimiters to oldDelims -- cleaning up

return steves_string -- you would not need this line, but for testing it's nice


I am sure that this could be tightened up but I thought it was educational to see it step by step.

You could certainly pass in any time you wanted-- does not have to be "current date." (Note that current date includes the time too. You peel off the "time" part of a date by asking for "the time string" of it.