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.

inside custom component

Native Development

Reply
Developer
citrinetiger
Posts: 54
Registered: ‎12-04-2012
My Device: Q10
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: 1,511
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

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"

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
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 -- (BB10 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.
Developer
citrinetiger
Posts: 54
Registered: ‎12-04-2012
My Device: Q10
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.