DWORD string2long(CString str_time) { //Format("%Y-%m-%d %H:%M:%S") //格式:2013-01-01 12:12:12 struct tm stTime; //定义tm类型变量 sscanf_s(str_time, "%d-%d-%d %d:%d:%d", &stTime.tm_year, &stTime.tm_mon, &stTime.tm_mday, &stTime.tm_hour, &stTime.tm_min, &stTime.tm_sec); //强制转换为char*,再使tm变量获取时间值 stTime.tm_year = stTime.tm_year - 1900; stTime.tm_mon = stTime.tm_mon - 1; //转换相对1900.01的时间长度 time_t t_time = mktime(&stTime); /*TRACE("\n\n%d/%d/%d %d:%d:%d\n",stTime.tm_year + 1900,stTime.tm_mon + 1,stTime.tm_mday, stTime.tm_hour,stTime.tm_min,stTime.tm_sec);*/ //TRACE("%d\n", t_time); return t_time; } CString long2string(DWORD d_time) { time_t t_time = (time_t)d_time; struct tm mTime; //定义tm类型指针 localtime_s(&mTime,&t_time); //获取时间 CString str_time; str_time.Format("%d-%d-%d %d:%d:%d\n",mTime.tm_year + 1900,mTime.tm_mon + 1,mTime.tm_mday, mTime.tm_hour,mTime.tm_min,mTime.tm_sec); //TRACE(str_time+"\n"); return str_time; } CString getLocalTime() { //CTime::GetTickCount() 获取系统时间精确到秒 CString str_time; str_time.Format(_T("%d"),CTime::GetTickCount()); return str_time; } struct MyDate long2time(DWORD d_time) { time_t t_time = (time_t)d_time; struct tm mTime; //定义tm类型指针 struct MyDate mydate; localtime_s(&mTime,&t_time); //获取时间 mydate.year = mTime.tm_year + 1900; mydate.month = mTime.tm_mon + 1; mydate.day = mTime.tm_mday; mydate.hour = mTime.tm_hour; mydate.minute = mTime.tm_min; mydate.second = mTime.tm_sec; #ifdef DEBUG TRACE("%d/%d/%d %d:%d:%d\n",mydate.year,mydate.month,mydate.day, mydate.hour,mydate.minute,mydate.second); #endif return mydate; } DWORD currentTimeSeconds() { CString str; str.Format(_T("%ld"),CTime::GetTickCount()); DWORD d_value = _ttol(str); return d_value; } CString GetFomatTime() { CString str; CTime time; time = CTime::GetCurrentTime(); str = time.Format("%Y-%m-%d %H:%M:%S"); return str; } CString GetTimeFileName() { CString str; CTime time; time = CTime::GetCurrentTime(); str = time.Format("%Y%m%d%H%M%S"); return str; }