Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Contributor
citrinetiger
Posts: 44
Registered: ‎12-04-2012
My Carrier: Verizon
Accepted Solution

How to Show Current Time?

Hi all!

 

I know how to get the current Date/ Time like this:

 

Label {

text: {

new Date();

}

}

 

in which the label displays, for example : "2013-02-10T15:52:28"

 

how do I ONLY display the hour(15)?  

 

Thanks,

 

-Ali

Please use plain text.
Developer
Zmey
Posts: 888
Registered: ‎12-18-2012

Re: How to Show Current Time?

Hi,

 

Use Qt formatDateTime method:

http://qt-project.org/doc/qt-4.8/qml-qt.html#formatDateTime-method

 

For hours:

var hours = Qt.formatDateTime(new Date(), "hh"); // or "h"

 

Please use plain text.
Developer
peter9477
Posts: 5,617
Registered: ‎12-08-2010
My Carrier: none

Re: How to Show Current Time?

Alternatively you could just use the methods available on that Date instance, as in text: (new Date()).getHours()

The only problem with that is, I believe, that it won't update automatically, so you'll likely need to investigate the use of QTimer as well, to trigger a periodic refresh of the value.

Peter Hansen -- (PlayBook and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Contributor
citrinetiger
Posts: 44
Registered: ‎12-04-2012
My Carrier: Verizon

Re: How to Show Current Time?

Thank you both for your suggestions! :smileyhappy:

 

I ended up using this code:

 

 Label{
                text: {
                var hours = Qt.formatDateTime(new Date(), "hh");
                return hours;
                }
            }

 

Please use plain text.