// test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <fstream> #include <string.h> #include <iostream> #include <io.h> #include<atltime.h> using namespace std; #define BUFSIZE 1024 #define PLANFILE "planTast.ini"; #define MANUALFILE "manualRun.ini"; CTime String2Time(CString s) { int iY,iMon,iD,iH,iM,iSS; int len; len=s.GetLength(); if(len==8) { CTime t1; t1=CTime::GetCurrentTime(); iY=t1.GetYear(); iMon=t1.GetMonth(); iD=t1.GetDay(); CString h,m,ss; h=s.Mid(0,2); iH=atoi(h); m=s.Mid(3,2); iM=atoi(m); ss=s.Mid(6,2); iSS=atoi(ss); } else if(len==19) { CString y,mon,d,h,m,ss; y=s.Mid(0,4); iY=atoi(y); mon=s.Mid(5,2); iMon=atoi(mon); d=s.Mid(8,2); iD=atoi(d); h=s.Mid(11,2); iH=atoi(h); m=s.Mid(14,2); iM=atoi(m); ss=s.Mid(17,2); iSS=atoi(ss); } else { CTime t2; t2=CTime::GetCurrentTime(); iY=t2.GetYear(); iMon=t2.GetMonth(); iD=t2.GetDay(); iH=t2.GetHour(); iM=t2.GetMinute(); iSS=t2.GetSecond(); } CTime t(iY,iMon,iD,iH,iM,iSS); return t; } int main() { /* FILE* fd; char buffer[BUFSIZE]; if(_access("1.txt",00) == -1) return -1; if (( fd = fopen("1.txt","rt")) == NULL) return -1; while(fgets(buffer,BUFSIZE,fd)) { cout <<buffer <<endl; } fclose(fd); unlink("1.txt"); */ //CString strTime("2007-05-23"); CString strTime("2007-05-23 02:23:12"); CTime cTime = String2Time(strTime); CTime time = CTime::GetCurrentTime(); //获取当前时间 CTime time1(time.GetYear(),time.GetMonth()-3,time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond()); cout <<time.GetYear()<<time.GetDay() << time.GetHour() <<endl; cout <<cTime.GetMonth()<<cTime.GetDay()<<endl; CTimeSpan tmr3 = cTime - time; LONGLONG longsum = tmr3.GetTotalSeconds(); if (longsum < 10 && longsum>-10) { cout << "OK" << endl; } return 0; }