//时间戳转北京时间字串 CString getLocalDate(__int64 timestamp) { timestamp += 28800;//GTM偏移8个时区得到北京时间 tm p; gmtime_s(&p, ×tamp); char s[80]; strftime(s, 80, "%Y-%m-%d %H:%M:%S", &p); return CString(s); } //北京时间字串转时间戳 __int64 getTimestamp(CString strInputTime) { COleVariant vtime(strInputTime); vtime.ChangeType(VT_DATE); COleDateTime cOleTime = vtime; SYSTEMTIME systime; VariantTimeToSystemTime(cOleTime, &systime); //时间戳最小值为北京时间:1970-01-01 08:00:00 if (systime.wYear <= 1970 && systime.wMonth <= 1 && systime.wDay <= 1 && systime.wHour <= 7 && systime.wMinute <= 59 && systime.wSecond <= 59) return 0; CTime cTimeFromDB(systime); __int64 timestamp = cTimeFromDB.GetTime();//CTime->时间戳 return timestamp; }
原文:https://www.cnblogs.com/rcg714786690/p/14957927.html