datepicker / textfield / 24hr format !?

Hi Folks,

first of all: compliments to all of you. I’ve been reading around here for a bit, found quite a few useful hints for my considerable small problems and enjoyed the nice and helpful attitude of the active forum members.

Now I’ve got a problem that seems a bit tricky to me and I couldn’t find anything on the net so far:

1.) What I need in general is a field where I can enter a number directly that is interpreted as time (e.g. 1023 would be interpreted as 00:10:23) and that can be as well changed by 1-3 steppers (3 would be ideal (h / m /s))

2.) Since I could find no better, I decided to use the date picker control. It has only one stepper but seems more or less suitable for my needs.

3.) Now comes the point where I arrived so far: when I read the contents of the date picker as time string, i always get something like ‘01:01:01 AM’. I would not mind if I had only 12 hours max. to enter the time, but I cannot have the AM/PM at the end.

4.) Here’s the question: How can I convert the content from date picker to the 24hr format OR is there any (maybe a lot smarter) way of entering timecodes?

here’s (more or less) my code:

[code]tell window “dMain”
set the_date to content of control “myTimecode”
set the_time to the time string of the_date
end tell

→ the_time = “01:02:03 AM”[/code]
The AM has to go _and I have problems since 12:00:00 AM in 12h format would be 00:00:00 in 24h format ( I need the 00:00:00 ).

Thanks for any hint, and please excuse any errors in my English.

sbx

Model: pb g4 al
AppleScript: xcode 2.2
Browser: Firefox 1.0.7
Operating System: Mac OS X (10.4)

The date picker will use the style that is set in the System Preferences (International pane).

Hi Bruce,

thanks for the hint. You’re completely right in terms of displaying the time in the UI. But internally, Applescript is always using the 12hr format.

But I think maybe a date formatter can do the trick. I’ll try later…

sbx

Possibly, but consider this:

get time string of (current date)

With my current settings this returns: “10:15:11 AM”

However, changing my time settings to a 24-hour clock returns. well, it’s too early to check it, but it does return what you would expect.

That said, a date formatter might be better for what you’re doing.

You could also try something like this:

set theTime to time of (current date)

set theHour to zeroPad(round (theTime / hours) rounding down)
set theMinute to zeroPad(round ((theTime mod hours) / minutes) rounding down)
set theSecond to zeroPad(round (((theTime / minutes) - result) * 60) rounding down)

set theTime to theHour & ":" & theMinute & ":" & theSecond

on zeroPad(thisNumber)
	return text -2 thru -1 of ("0" & thisNumber)
end zeroPad

Just replace “current date” with the date object from the date picker.

Using a technique I learned from Nigel Garvey: (again replacing current date with the date you want)

tell time of (current date) to tell 1000000 + it div hours * 10000 + it mod hours div minutes * 100 + it mod minutes as string to text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7

Or you could attach a date formatter to a text field in Interface Builder.