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
New Contributor
Posts: 8
Registered: ‎01-02-2013
My Device: playbook, bb10
My Carrier: starhub
Accepted Solution

problem about getting current date in qml

hi, everyone

 

I am trying to get the current date in c++ and qml, and i used the QDate class, but it still have some problems:

code:

=====================================================

QDate* nowdate = new QDate;
QDeclarativePropertyMap* nowdateMap= new QDeclarativePropertyMap;
nowdateMap->insert("date",QVariant(nowdate->currentDate()));
qml->setContextProperty("nowdateMap", nowdateMap);

===========================================================

 

after setting the nowdateMap, i am able to get the date in the app, but the format is really wierd, i did not use QDatetime, but the restult shows like "2013-1-3T00:00:00", how could i get rid of the final "T00:00:00"? or is there a better way to get the current date?

 

 thanks

New Contributor
Posts: 8
Registered: ‎01-02-2013
My Device: playbook, bb10
My Carrier: starhub

Re: problem about getting current date in qml

i already fix it

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: problem about getting current date in qml

Please share your solution.

Andrey Fidrya, @zmeyc on twitter
New Contributor
Posts: 8
Registered: ‎01-02-2013
My Device: playbook, bb10
My Carrier: starhub

Re: problem about getting current date in qml

QDate nowdate = QDate::currentDate();

QString nowdatestring=nowdate.toString();// to get the string format of date, u can set the form in toString(), u can //search it  
QDeclarativePropertyMap* nowdateMap= new QDeclarativePropertyMap;
nowdateMap->insert("date",QVariant(QString(nowdatestring)));
qml->setContextProperty("nowdateMap", nowdateMap);

 

 

then in the qml file, using nowdateMap.date will do.

Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: problem about getting current date in qml

you can do that in qml(javascript) too wihout the c+++ part:

 

var date = new Date();

Qt.formatDateTime(date,'yyyy-MM-dd')

 

(please mark this post as solved since you already posted a solution)

Highlighted
New Contributor
Posts: 8
Registered: ‎01-02-2013
My Device: playbook, bb10
My Carrier: starhub

Re: problem about getting current date in qml

ok.. seems ur method is easier.. i will try later

sorry forget to do that, i will change the status.