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 Developer
Posts: 4
Registered: ‎07-21-2013
My Device: Blackberry Z10
My Carrier: AT&T
Accepted Solution

How to get current timestamp by C++ in BB10 project

Please help me how to get current timestamp by C++. Thank for your help!

Regular Contributor
Posts: 94
Registered: ‎12-02-2011
My Device: non-Blackberry user
My Carrier: none

Re: How to get current timestamp by C++ in BB10 project

QTime::currentTime()

New Developer
Posts: 4
Registered: ‎07-21-2013
My Device: Blackberry Z10
My Carrier: AT&T

Re: How to get current timestamp by C++ in BB10 project

Following your suggestion,

QTime is only during a day.  http://developer.blackberry.com/cascades/reference/qtime.html#details

I found "QDateTime" from API references:  http://developer.blackberry.com/cascades/reference/qdatetime.html#toTime_t

 

QDateTime now = QDateTime::currentDateTime();
long timestamp = now.toTime_t();

 

But I got an error. I searched but no result is clear: 

 

- variable 'QDateTime now' has initializer but
incomplete type
- incomplete type 'QDateTime' used in nested name
specifier

 

I'm a newbie. So I'm grateful to you for your help :smileyhappy:

Developer
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10
My Carrier: MTS

Re: How to get current timestamp by C++ in BB10 project

Add

#include <QDateTime>

 

to your source file.

 

-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Developer
Posts: 16,637
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to get current timestamp by C++ in BB10 project

it is usually easier to use the static methods, like
https://developer.blackberry.com/cascades/reference/qdatetime.html#currentMSecsSinceEpoch
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 4
Registered: ‎07-21-2013
My Device: Blackberry Z10
My Carrier: AT&T

Re: How to get current timestamp by C++ in BB10 project

Thank you for your help. It works perfectly!