[Interest] Setting timezone for QDateTime::currentDateTime()

Reinhardt Behm rbehm at hushmail.com
Sun Aug 9 01:16:10 CEST 2015


On Saturday 08 August 2015 19:59:43 Tom Isaacson wrote:
> I'm running Qt 4.8.2 on a Freescale BSP using Linux 3.0.17. The
> documentation for QDateTime::currentDateTime() says "Returns the current
> datetime, as reported by the system clock, in the local time zone." We use
> settimeofday() [http://linux.die.net/man/2/settimeofday] to set the system
> clock but the documentation says the timezone struct is obsolete and should
> not be used. So how can we programatically set the timezone in a way that
> Qt will recognise?
> 
> Tom Isaacson
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

Hi Tom,

This is what I do in a GPS receiver module:

	if (m_setRtc && m_posInfo.has(GeoPositionInfo::TimeStamp))
	{
		struct timeval tv;
		struct timezone tz;
		gettimeofday(&tv, &tz);
		tv.tv_sec = m_posInfo.timestamp().toTime_t();
		tv.tv_usec = 0;
		settimeofday(&tv, &tz);
		settimeofday(&tv, 0);
		system("hwclock --systohc");

		qDebug() << Q_FUNC_INFO << "valid date/time UTC " + 
m_posInfo.timestamp().toString(Qt::ISODate);
		m_setRtc = false;
		FILE *f = fopen("/tmp/rtcset", "w");	// create to signal it is set
		if (f)
		{
			fclose(f);
		}
	}

-- 
Best Regards

Reinhardt Behm





More information about the Interest mailing list