Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 386
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK
Accepted Solution

Changing label based on time

[ Edited ]


I have a simple label with the text showing a time; I was wondering: if it would be possible to change the time - of the label (which is inputted via XML) to the user's current time zone and if so, how would I go about doing that?



property alias fixtureInfo: fixtureText.text
    property alias timeInfo: timeText.text
    property alias stadiumInfo: stadiumText.text

Header {
                title: qsTr("Time (GMT - 3)")
            Container {
                leftPadding: 20
                rightPadding: 20
                Label {
                    id: timeText
                    multiline: true
                    textStyle.base: bodyStyle.style



<continent title="Thursday 12 June 2014"> 
        <listItem title="Brazil vs Croatia">
        <fixtureInfo>Brazil vs Croatia</fixtureInfo>
        <timeInfo>17:00PM (Local Time)</timeInfo>
        <stadiumInfo>Arena de Sao Paulo</stadiumInfo>

Thanks Smiley Happy

Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: Changing label based on time

here are some tips:


to get the name of the current timezonbe you can ask the CalendarService


 here's some code to get some useful values from current time

QVariantMap MonitorTime::nowDateTimeInfo() {
	QVariantMap map;
	QDateTime now = QDateTime::currentDateTime();
	QString nowIso = now.toString(Qt::ISODate);
	QString nowUtcIso = now.toUTC().toString(Qt::ISODate);
	// cut the seconds
	nowUtcIso = nowUtcIso.split("T").at(0) + "T"
			+ nowUtcIso.split("T").at(1).left(6) + "00Z";
	QString day = nowIso.left(10);
	QLocale locale = QLocale().system();
	QString dayFormatted = locale.toString(QDate::fromString(day, Qt::ISODate),
	QString hhmm = nowIso.split("T").at(1).left(5);
	QString timeZone = mConnectedCalendar->currentCalendarTimeZone();
	QString suffix = currentTimeZoneSuffix(now);
	map.insert("weekday", weekdayLocalized(day));
	map.insert("day", day);
	map.insert("dayFormatted", dayFormatted);
	map.insert("hhmm", hhmm);
	map.insert("timeZone", timeZone);
	map.insert("suffix", suffix);
	map.insert("iso", isoDate(day, hhmm, suffix));
	map.insert("isoUTC", nowUtcIso);
	return map;


QString MonitorTime::currentTimeZoneSuffix(const QDateTime& dateTime) {
	QDateTime dt = dateTime;
	int minutesOffset = dt.secsTo(dateTime) / 3600 * -1;
	QString suffix;
	if (minutesOffset > 0) {
		suffix = "+";
	} else {
		suffix = "-";
	int hoursOffset = abs(minutesOffset) / 60;
	if (hoursOffset < 10) {
	minutesOffset = abs(minutesOffset) - (hoursOffset * 60);
	if (minutesOffset == 30) {
	} else {
	return suffix;


perhaps you get some ideas from the code

easiest way to see what's in the Map use JsonDataAccess to write the content into a file

ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner