11-12-2020 00:55
11-12-2020 00:55
I am trying to create a clockface using the Fitbit OS Simulator, but have come across an issue. I have set up the AM/PM label to appear when switching between 24h an 12h time formats, but when I have the time set to 12AM it shows 0:00AM instead of 12AM. It should show 12AM when in 12h format.
The code I have for the AM/PM label is as follows:
if (preferences.clockDisplay === "12h") {
// 12h format
if(hours > 12) {
ampmLabel.text = "PM";
hours -= 12;
} else if (hours == 12) {
ampmLabel.text = "PM";
} else if (hours < 12) {
ampmLabel.text = "AM";
}
} else {
// 24h format
ampmLabel.text = "";
hours = util.zeroPad(hours);
}
Can anyone help with this? Thanks.
11-12-2020 01:08
11-12-2020 01:08
In your hours<12 section, consider something like
if (!hours) hours = 12
11-12-2020 01:29
11-12-2020 01:29
Thank you. That has worked.