09-05-2017 17:58 - edited 09-05-2017 18:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-05-2017 17:58 - edited 09-05-2017 18:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
How do we detect whether the Ionic has been set to 12 or 24 hour display mode?
Will need this for digital clock faces.
Answered! Go to the Best Answer.
Accepted Solutions
09-05-2017 22:56 - edited 11-09-2017 09:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


09-05-2017 22:56 - edited 11-09-2017 09:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
import { preferences } from "user-settings"; console.log(preferences.clockDisplay);
(edited)
09-05-2017 22:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-05-2017 22:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I have found the User-settings API in the reference documentation.
So, would I access it with something like this:
import (UserSettings) from "User-settings";
var settings = new UserSettings();
if (settings.clockDisplay === "12h") .....

09-05-2017 22:56 - edited 11-09-2017 09:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


09-05-2017 22:56 - edited 11-09-2017 09:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
import { preferences } from "user-settings"; console.log(preferences.clockDisplay);
(edited)
11-09-2017 09:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-09-2017 09:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@JonFitbit wrote:import { Preferences } from "user-settings"; console.log(Preferences.clockDisplay);
preferences needs to be lowercase.
import { preferences } from "user-settings"; console.log(preferences.clockDisplay)
I hate to be "that guy"; but copying your sample caused a bit of frustration as it would fail to load clockdisplay from undefined.

11-09-2017 09:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-09-2017 09:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks, I've fixed my reply

11-28-2017 21:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-28-2017 21:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm sorry; I'm not familiar with writing code. I just used the help instructions fitbit provided in order to make my own clock face. This (below) is the index code. Where do I put the code you provided in order to change my time from 24-hour to 12-hour? I'm sorry; I imagine this is a dumb question but I just can't figure it out.
import clock from "clock";
import document from "document";
import * as util from "../common/utils";
// Update the clock every minute
clock.granularity = "minutes";
// Get a handle on the <text> element
let myLabel = document.getElementById("myLabel");
// Update the <text> element with the current time
function updateClock() {
let today = new Date();
let hours = today.getHours();
let mins = util.zeroPad(today.getMinutes());
myLabel.text = `${hours}:${mins}`;
}
// Update the clock every tick event
clock.ontick = () => updateClock();

11-29-2017 10:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-29-2017 10:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
@Jennthemom wrote:
I'm sorry; I'm not familiar with writing code. I just used the help instructions fitbit provided in order to make my own clock face. This (below) is the index code. Where do I put the code you provided in order to change my time from 24-hour to 12-hour? I'm sorry; I imagine this is a dumb question but I just can't figure it out.
import clock from "clock";
import document from "document";import * as util from "../common/utils";
// Update the clock every minute
clock.granularity = "minutes";// Get a handle on the <text> element
let myLabel = document.getElementById("myLabel");// Update the <text> element with the current time
function updateClock() {
let today = new Date();
let hours = today.getHours();
let mins = util.zeroPad(today.getMinutes());myLabel.text = `${hours}:${mins}`;
}// Update the clock every tick event
clock.ontick = () => updateClock();
Try this:
import clock from "clock";
import document from "document";
import * as util from "../common/utils";
import { preferences } from "user-settings";
// Update the clock every minute
clock.granularity = "minutes";
// Get a handle on the <text> element
let myLabel = document.getElementById("myLabel");
// Update the <text> element with the current time
function updateClock() {
let today = new Date();
let hours = today.getHours();
if (preferences.clockDisplay === "12h") {
hours = (hours + 24) % 12 || 12;
}
let mins = util.zeroPad(today.getMinutes());
myLabel.text = `${hours}:${mins}`;
}
// Update the clock every tick event
clock.ontick = () => updateClock();
11-29-2017 10:14 - edited 11-29-2017 11:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-29-2017 10:14 - edited 11-29-2017 11:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Ah! Thank you so much! That did it! You are awesome! There is absolutely no way I would ever have figured out how to customize my watch face without you. I really appreciate your help.

11-29-2017 11:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-29-2017 11:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Jennthemom wrote:
Ah! Thank you so much! That did it! You are awesome! There is absolutely no way I would ever have figured out how to customize my watch face without you. I really appreciate your help.
Thanks! If you're on Twitter, you should share your creation with the world. #made4fitbit

01-04-2018 17:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2018 17:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks! I also prefer the 12 hour time and the solution worked for me. However, the clock face doesn't show am or pm after the time. Is there a way to add that?

01-04-2018 17:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2018 17:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Here is how I do it:
let ampm = " am" if (preferences.clockDisplay == "12h"){
if (hours > 12){ ampm = " pm"; hours -= 12; } else if (hours == 12){ ampm = " pm" } else if (hours == 0 && ampm == " am"){ hours += 12; } } else { ampm = "" } clockLabel.text = `${hours}:${mins}${ampm}`;
01-04-2018 18:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2018 18:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Worked perfectly! Thanks so much.

09-06-2018 02:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-06-2018 02:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
// Output the date object
console.log(evt.date.toString());
};
import * as simpleActivity from "./simple/activity";
import * as simpleClock from "./simple/clock";
import * as simpleHRM from "./simple/hrm";
import { preferences } from "user-settings";
import * as util from "../common/utils";
let txtHRM = document.getElementById("txtHRM");
let iconHRM = document.getElementById("iconHRM");
let imgHRM = iconHRM.getElementById("icon");
let statsCycle = document.getElementById("stats-cycle");
let statsCycleItems = statsCycle.getElementsByClassName("cycle-item");
txtDate.text = data.date;
}
simpleClock.initialize("minutes", "longDate", clockCallback);
statsCycleItems.forEach((item, index) => {
let img = item.firstChild;
let txt = img.nextSibling;
txt.text = data[Object.keys(data)[index]].pretty;
// Reposition the activity icon to the left of the variable length text
img.x = txt.getBBox().x - txt.parent.getBBox().x - img.width - 7;
});
}
simpleActivity.initialize("seconds", activityCallback);
txtHRM.text = `${data.bpm}`;
if (data.zone === "out-of-range") {
imgHRM.href = "images/heart_open.png";
} else {
imgHRM.href = "images/heart_solid.png";
}
if (data.bpm !== "--") {
iconHRM.animate("highlight");
}
}
simpleHRM.initialize(hrmCallback);
clock.granularity = "minutes";
const myLabel = document.getElementById("myLabel");
clock.ontick = (evt) => {
let today = evt.date;
let hours = today.getHours();
if (preferences.clockDisplay === "12h") {
// 12h format
hours = hours % 12 || 12;
} else {
// 24h format
hours = util.zeroPad(hours);
}
let mins = util.zeroPad(today.getMinutes());
myLabel.text = `${hours}:${mins}`;
}
import document from "document";
import clock from "clock";
myClock.text = ("0" + evt.date.getHours()).slice(-2) + ":" +
("0" + evt.date.getMinutes()).slice(-2) + ":" +
("0" + evt.date.getSeconds()).slice(-2);
};

08-08-2020 13:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-08-2020 13:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
i dont really know where to ask this so i ll just relpy here. im having a hard time figuring out how to make a versa detect 12 hour clock vs 24 hour clock, it seem to be stuck on 24. I just dont know what im doing to be honest. this is what i have in the index page.
import clock from "clock";
import { preferences } from "user-settings";
import document from "document";
import { HeartRateSensor } from "heart-rate";
import * as util from "../common/utils";
import { today } from "user-activity";
console.log(preferences.clockDisplay);
// Update the clock every minute
clock.granularity = "seconds";
// Get a handle on the <text> element
let date = document.getElementById("date");
let time = document.getElementById("time");
let hBpm = document.getElementById("heartRate");
var hrm = new HeartRateSensor();
hrm.onreading = function(){
//hBpm.text = hrm.heartRate + " BPM";
//console.log("Current heart rate: " + hrm.heartRate);
}
hrm.start();
// Update the <text> element with the current time
function updateClock() {
let today = new Date();
date.text = util.getDateString(today);
time.text = util.getTimeString(today);
hBpm.text = hrm.heartRate + " BPM";
}
// Update the clock every tick event
clock.ontick = () => updateClock();

08-08-2020 13:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-08-2020 13:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
The question has already been answered above (clockDisplay). Your getTimeString() function needs to take this into account.
Gondwana Software

10-06-2020 15:07 - edited 08-04-2021 20:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-06-2020 15:07 - edited 08-04-2021 20:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
This is the way I find it efficient. Put this into your index.js:
AMPM.text = today.getHours() < 12 ? "AM" : "PM";}
If this answer works please mark this post as a Best Answer. ~ K.K Designs

