Qt獲取當前時間


1 使用QDateTime類(毫秒精度)

QDateTime current_date_time = QDateTime::currentDateTime();
QString current_date = current_date_time.toString("yyyy-MM-dd hh:mm::ss.zzz");

2 使用QTime類

QTime current_time = QTime::currentTime();
int hour = current_time.hour();        //當前的小時
int minute = current_time.minute();    //當前的分
int second = current_time.second();    //當前的秒
int msec = current_time.msec();        //當前的毫秒

 3 使用GetLocalTime函數(毫秒精度)

SYSTEMTIME sys;
GetLocalTime(&sys);
printf("%4d/%2d/%2d %2d:%2d:%2d.%3d\n",sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM