1. time_t systemtime_to_time_t(const SYSTEMTIME& st)
  2. {
  3. struct tm gm = {st.wSecond, st.wMinute, st.wHour, st.wDay, st.wMonth-1, st.wYear-1900, st.wDayOfWeek, 0, 0};
  4. return mktime(&gm);
  5. }
  6. SYSTEMTIME time_t_to_systemtime(time_t t)
  7. {
  8. tm temptm = *localtime(&t);
  9. SYSTEMTIME st = {1900 + temptm.tm_year,
  10. 1 + temptm.tm_mon,
  11. temptm.tm_wday,
  12. temptm.tm_mday,
  13. temptm.tm_hour,
  14. temptm.tm_min,
  15. temptm.tm_sec,
  16. 0};
  17. return st;
  18. }

https://blog.csdn.net/hellokandy/article/details/51329446

MFC版本的计算两个SYSTEMTIME之间的时间差,返回毫秒:

  1. __int64 TimeDiff(SYSTEMTIME left, SYSTEMTIME right)
  2. {
  3. CTime tmLeft(left.wYear, left.wMonth, left.wDay, 0, 0, 0);
  4. CTime tmRight(right.wYear, right.wMonth, right.wDay, 0, 0, 0);
  5. CTimeSpan sp = tmLeft - tmRight;
  6. long MillisecondsL = (left.wHour*3600 + left.wMinute*60 + left.wSecond)*1000 + left.wMilliseconds;
  7. long MillisecondsR = (right.wHour*3600 + right.wMinute*60 + right.wSecond)*1000 + right.wMilliseconds;
  8. return  (__int64)sp.GetDays()*86400000 + (MillisecondsL - MillisecondsR);//此处返回毫秒
  9. }

https://blog.csdn.net/hellokandy/article/details/51329183

04-19 20:35