SYSTEMTIME 加了30秒,感觉结果不对,请教
SYSTEMTIME sysnow;
GetLocalTime(&sysnow);
ULARGE_INTEGER fstartdate;/*FILETIME*/
bool irev = SystemTimeToFileTime(&sysnow,(FILETIME*)&fstartdate);
assert(irev);
fstartdate.QuadPart=fstartdate.QuadPart+(30*1000000000/100);
// 100 / 1000000000
SYSTEMTIME t;
irev =FileTimeToSystemTime((FILETIME*)&fstartdate,&t);
assert(irev);
system("pause");
//1纳秒=1000皮秒
//1纳秒 =0.001 微秒
//1纳秒=0.000 001毫秒
//1纳秒=0.000 000 001秒
fstartdate.QuadPart 单位 100纳秒
[解决办法]
30*1000000000溢出int
用30*1000000000ll
[解决办法]
#include <afxdisp.h>
#include <stdio.h>
#include <windows.h>
COleDateTime t;
COleDateTimeSpan h8;
SYSTEMTIME st;
FILETIME ft;
int main(int argc, char **argv) {
if (argc<2) {
Usage:
printf("Usage:%s {hexFILETIME
[解决办法]
"YYYY-MM-DD hh:mm:ss"}\n",argv[0]);
return 2;
}
h8=COleDateTimeSpan(0,8,0,0);//8 hours
if (t.ParseDateTime(argv[1])) {
t-=h8;
if (t.GetAsSystemTime(st)) {
if (SystemTimeToFileTime(&st,&ft)) {
t+=h8;
printf("%016I64x <==> %s\n",ft,t.Format("%Y-%m-%d %H:%M:%S"));
return 1;
} else {
printf("SystemTimeToFileTime failed!\n");
return 3;
}
} else {
printf("GetAsSystemTime failed!\n");
return 3;
}
} else {
if (1==sscanf(argv[1],"%016I64x",&ft)) {
t=COleDateTime(ft);
printf("%016I64x <==> %s\n",ft,t.Format("%Y-%m-%d %H:%M:%S"));
return 0;
} else {
goto Usage;
}
}
}
#include <afxdisp.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
SYSTEMTIME st;
COleDateTime t;
COleDateTime b;
COleDateTimeSpan ts;
time_t tt;
COleDateTime n;
CString s;
GetSystemTime(&st);
t=COleDateTime(st);
b=COleDateTime(1970,1,1,0,0,0);
ts=t-b;
tt=(time_t)(ts.GetTotalSeconds());
n=COleDateTime(tt);
s=n.Format("%Y-%m-%d %H:%M:%S");
printf("%s\n",s);
return 0;
}