Looking for methods to call TimePicker selection time components to be displayed in 12hr format

I've seen a lot of ways to accomplish this but all seem pretty different from what I feel like should be a simple answer. My current project is an Alarm app. The only issue I'm having is time formatting coming from the TimePicker specifically. Currently the user taps a time picker button, then .AfterTimeSet should set a label to the selected time.

I understand there are many formatting options for time within the Clock's functions but I'm struggling to find how this would cross over to the picker, if it can at all. All I need is the result of a 12hr format from the TimePicker.Hour and .Minute.

At first I was just running with using .Hour/.Minute; My .AfterTimeSet file currently shows the format method. I bloated my code with globals trying to do conversion shenanigans. As such, my logic comes from taking the time picker hour/minute, set them to a global for Clock validation later, convert that time into what is my attempt at making a 12hr format via Convert_time procedure, two blocks one with globals and one with the original picker calls. Regular calls were working well enough but I kept getting strange outcomes related to 12AM/12PM, especially if 0's are involved due to the 24hr format. So I switched to the bloated global variable method thinking it was an issue of passing the specific TimePicker value (My first attempts with conversion were inside the AfterTimeSet procedure, so I made it's own procedure trying to figure this out).

Most posts I can find end up using the Clock date procedures to present the time. Would setting the label to Clock.Now during the AfterTimeSet be accurate if the label is only showing HH:MM?

The only thing I can think of left is trying to modify my current method to force in 0's if they're missing, such as 00 rather than 0:XX for 12AM. I did see a method of using some math to convert minutes/hours/seconds and shift it around that way... But again, I've got to be missing something simple right?

You can check here for more patterns:

1 Like

Ah, that makes a lot of sense. That's perfect, thank you! Saved me a lot of code space. I didn't realize it could access other instants outside of direct clock elements.

Note that the timePicker instant only gives you back the time, it does not give you a complete instant....

1 Like

and not possible for set second

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.