获取本地时间

1 使用QDateTime类(毫秒精度

  1. QDateTime current_date_time = QDateTime::currentDateTime();

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

2 使用QTime类

  1. QTime current_time = QTime::currentTime();

  2. int hour = current_time.hour(); //当前的小时

  3. int minute = current_time.minute(); //当前的分

  4. int second = current_time.second(); //当前的秒

  5. int msec = current_time.msec(); //当前的毫秒

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

  1. SYSTEMTIME sys;

  2. GetLocalTime(&sys);

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

点我跳转原作者