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
Posts: 15
Registered: ‎12-20-2012
My Device: BlackBerry 10 Dev Alpha
My Carrier: Rogers
Accepted Solution

Incorrect utcOffset from QDateTime::currentDateTimeUtc()

Hey everyone,

 

I am currently attempting to pull the local utc offset in order to calculate the difference between local time and scheduled events being pulled externally. I construct the scheduled events just fine and they produce the accurate utc offset. However when I create a QDateTime object using the QDateTime::currentDateTimeUtc() function it gives me a utcOffset of 0 (it should be -5). I have checked and the timezone on my Dev Alpha device, and it is correctly set.

 

Am I just missing something? I have tried to look up the documentation behind the utcOffset() function but the QDateTime documentation on the Cascades Developer site doesn't even list the function utcOffset() (QDateTime). If there is another way to get the timezone information in C++ it would also work just fine, as long as I can get the offset value.

 

Below is the code I am using (slightly edited so as to include only what is prevalent)

 

QDateTime todayDate = QDateTime::currentDateTimeUtc();

//Loop through each item in the input data
for ( QVariantList indexPath = dataModel->first(); !indexPath.isEmpty();
	indexPath = dataModel->after(indexPath) )
{
	//Retrieve the item
	QVariant item = dataModel->data(indexPath);

	QDateTime 	startDate 		= item.toMap().value("start").toDateTime();

	qDebug() << startDate.utcOffset();
	qDebug() << todayDate.utcOffset();	

}

 

The output  I receive in console is:

Debug: -18000 
Debug: 0 

 The -18000 is correct but the 0 should also read -18000.

 

Thanks for any help available.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Incorrect utcOffset from QDateTime::currentDateTimeUtc()

I think I am missing something.  This looks like it is working as designed.  I think you want:

QDateTime todayDate = QDateTime::currentDateTime();

Developer
Posts: 15
Registered: ‎12-20-2012
My Device: BlackBerry 10 Dev Alpha
My Carrier: Rogers

Re: Incorrect utcOffset from QDateTime::currentDateTimeUtc()

I have also tried that, but to no avail. I receive the same values.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Incorrect utcOffset from QDateTime::currentDateTimeUtc()

Apologies, that doesn't work as you have found out.

 

Does this help?

   

   

    QDateTime current = QDateTime::currentDateTime();
    QDateTime currentUTC = current.toUTC();  // QDateTime::currentDateTimeUtc();
    QString currentTimeUTCString = currentUTC.toString("yyyyMMddhhmmsszzz");
    QDateTime currentUTCConverted = QDateTime::fromString(currentTimeUTCString, "yyyyMMddhhmmsszzz");
    long diff = current.toMSecsSinceEpoch() - currentUTCConverted.toMSecsSinceEpoch();