PDA

View Full Version : Worldtimeclock and timezones issue



ehnuh
4th October 2012, 02:40
Hi, I have a project that involves making a clock plugin using Qt. I utilized the basic clock example from Qt where you put the offset hours to display the times of other countries namely USA and India. My current system time is the Philippines. Here is the code:

void ClockPanel::setTimer()
{

QTimer *timer = new QTimer(ui->digital_clock);
connect(timer,SIGNAL(timeout()),this,SLOT(displayD ate()));
timer->start(1000);

displayDate();


}
void ClockPanel::displayDate()
{

QDateTime date_time = QDateTime::currentDateTime();
date_time.addSecs(hoursOffset);
QString dateString = date_time.toString("dddd MMM d yy");

QTime time = QTime::currentTime();
time = time.addSecs(hoursOffset);
QString time_in_text = time.toString("hh mm ap");


if((time.second()%2) == 0)
{
time_in_text[2]=':';
}
ui->digital_clock->display(time_in_text);

ui->label_date->setText(dateString);

}



i have a function that sets the hoursOffset to get the USA and India times. Problem is I later realized that if the program is used with another time zone/country, the time displayed will be wrong. How do I go about making the program flexible if it is used in another timezone. The times I display are PHIL, USA and India.

Lesiok
4th October 2012, 06:38
Read about QDateTime::toUTC and QDateTime::toTimeSpec