AUGH!! Trying to figure out how to switch between 12 and 24 hours

Former Member
Former Member
Hello everyone,

Ok, I am trying to figure out how to switch from 12 to 24 hours based on the watch's settings. My plan is that if the watch is set at 12 hour, it will just display something like 1:30 (for day or night) and if it's set for 24 hours, it will display 1330 for 1:30pm.

I have been trying to figure out how to do it for the past several days but can't get it to work. The 24 hour time works fine, but the 12 hour is screwing up. It displays 12 midnight as 0:00 instead of 12:00 and 1pm as 13:00.

My lines are obviously wrong somewhere and I am wondering if anyone can take a look at it and see where it bust?

Much thanks in advance.

View.onUpdate(dc);

dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_BLACK);

var clockTime = Sys.getClockTime();
var hour = clockTime.hour;
var sys = Sys.getDeviceSettings().is24Hour;
if (sys==false) {
if (hour > 12) {
hour = hour - 12;
if (hour == 0) {hour = 12;}
}
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.drawText(0, 100, Gfx.FONT_LARGE, Lang.format("$1$:$2$", [clockTime.hour, clockTime.min.format("%02d")]), Gfx.TEXT_JUSTIFY_LEFT);
} else {
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.drawText(0, 100, Gfx.FONT_LARGE, Lang.format("$1$$2$", [clockTime.hour.format("%02d"), clockTime.min.format("%02d")]), Gfx.TEXT_JUSTIFY_LEFT);
}
  • Less space and memory usage.
    I fail to see the improvement over what Travis has already suggested, sorry.
  • Agreed. They have been very patient and helpful with someone who has no programming knowledge. Though I still can't code from scratch and have to figure out what is happening in other people's codes and cobbling together and changing lines from them, this has been a very educating experience. And I find myself getting a bit addicted the more I get into it.


    Impressed that with no programming experience you've gotten this far. That's determination! Sounds like you're getting the same bug most of us old timers got when we first started decades ago (and sounds like I might be the young one, having started in the early 80's).
  • (and sounds like I might be the young one, having started in the early 80's).


    I think I'm the old-timer, as when I got K&R in 78, it was for a college class in OS internals. You all can just call me "Grandpa Jim" if you want! :)

    jaesurn - one thing about coding is the more you do, the more you use "copy/paste" when doing something new. :) You'll move to having shared code for things you do all the time.. For example, if I'm doing a watchface, I have shared code for things like a move bar where I can just say

    MoveBar.draw()

    and give it a few parameters for screen location, color, height, etc., and not even think about doing that code. And if there is a bug, I fix it once and everything that uses it is fixed in the next build.

    I'm glad to help new folks!