QT 设置系统时间

Windows上实现:

    #include     
    #include     
      
    bool hStart::sDate(int   year,   int   mon,   int   day) {  
        SYSTEMTIME   st;  
        GetSystemTime(&st);  
        st.wYear=year;  
        st.wMonth=mon;  
        st.wDay=day;  
        //st.wHour=hour;  
        //st.wMinute=minute;  
       // st.wSecond=sec;  
        //st.wDayOfWeek= 0;  
        //st.wMilliseconds= 0;  
        return SetSystemTime(&st);  
    }  

Linux上实现:

qt-读取和修改系统时间

QTime ct = QTime::currentTime();

修改系统时间

// change the system time

    QDateTime dt = QDateTime::currentDateTime();

    dt.setTime(timeEditor->time());

    time_t tt = (time_t)dt.toTime_t();

    int r = stime(&tt);

    if (r)

    {

        if (errno == EPERM)

            QMessageBox::warning(this, "Error", "You don't have permission to change system time.");

    }


你可能感兴趣的:(QT)