Calculating Daylight saving and UTC offset in QT

void getTimeZoneOffset()
{


    QString UTC_offset;
    time_t current_time;
    time(&current_time);
    QString Daylighsaving ;

    struct tm *timeinfo = localtime(&current_time);

    double offset = (timeinfo->tm_gmtoff)/60;

    if (timeinfo->tm_isdst)
    {
        offset += 60;
        Daylighsaving = "1";
    }

    if (offset > 0)
    {
        offset = -offset;

    }

    else{

        offset = -(offset);
    }

    UTC_offset = QString::number(offset);

}

Comments

Popular posts from this blog

Dynamic Memory allocation in C++ for 1d, 2d and 3d array

Write Your Own String Class:

Printing the odd and even no using Pthread