本文介绍了使用C ++的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

有人可以用C或C ++代码帮助我吗?要求如下

我有一个格式为"2011-07-01 09:26:53"的日期值,我想将其与Windows中的系统时间进行比较,并找出它们之间的最大值

这将是很大的帮助.

谢谢与问候,
Lokesh

Hi Friends,

Can anybody help me with a C or C++ code. Requirement is as follows

I have a value of date in format "2011-07-01 09:26:53" and i want to compare it with the system time in windows and find the maximum between them

It will be a great help.

Thanks & Regards,
Lokesh

推荐答案

//Get Creation Date into SystemTime
				SYSTEMTIME prCreateDateTimeSys;
				prCreateDateTimeSys.wYear = GetIntFromString(strCreationDate,4,0);
				prCreateDateTimeSys.wMonth = GetIntFromString(strCreationDate,2,4);
				prCreateDateTimeSys.wDay = GetIntFromString(strCreationDate,2,6);
				prCreateDateTimeSys.wHour = GetIntFromString(strCreationDate,2,8);
				prCreateDateTimeSys.wMinute = GetIntFromString(strCreationDate,2,10);
				prCreateDateTimeSys.wSecond = GetIntFromString(strCreationDate,2,12);
				prCreateDateTimeSys.wMilliseconds = 0;			//Not Used
				prCreateDateTimeSys.wDayOfWeek = 0;				//Not Used

				//Finding Difference between 2 DateTime
				COleDateTime prTimeCreated(prCreateDateTimeSys.wYear,prCreateDateTimeSys.wMonth,
					prCreateDateTimeSys.wDay,prCreateDateTimeSys.wHour,prCreateDateTimeSys.wMinute,
					prCreateDateTimeSys.wSecond);

				//Process End Date
				COleDateTime prEndDateTimeSys = COleDateTime::GetCurrentTime();
				
				
				COleDateTimeSpan timeDiff = prEndDateTimeSys - prTimeCreated;


struct tm newTime = {0};
PSTR pszTime = "2011-07-01 09:26:53";

sscanf(pszTime, "%4d-%2d-%2d %2d:%2d:%2d", &newTime.tm_year,
    &newTime.tm_mon,
    &newTime.tm_mday,
    &newTime.tm_hour,
    &newTime.tm_min,
    &newTime.tm_sec
time_t timeValue = mktime(&newTime);
time_t timeNow = time(NULL);
// compare the two values here


CString szTime = _T("2010-07-01 09:26:53");
COleDateTime t;
if(t.ParseDateTime(szTime))
{
	t = t > COleDateTime::GetCurrentTime() ? t:COleDateTime::GetCurrentTime();
}
CString szMax = t.Format(_T("%A, %B %d, %Y"));


这篇关于使用C ++的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 05:49