Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Detecting 12am correctly

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.

Best Answer
0 Votes
2 REPLIES 2

In your hours<12 section, consider something like

if (!hours) hours = 12

 

Peter McLennan
Gondwana Software
Best Answer

Thank you. That has worked.

Best Answer
0 Votes