Quantcast
Viewing all articles
Browse latest Browse all 20

Date manipulation question

Here's an example of a routine I wrote to parse a date format we use.  You'd have to adjust it, of course, to fit your date format.  I pass a CString into this routine.

//// Converts an XML Timestamp to a CTime object// Timestamp format = CCYY-MM-DD HH:MM:SS//
CTime FromTimeStamp(LPCTSTR cTimeStamp)
{
	CTime cTime = CTime::GetCurrentTime();if(!(cTimeStamp == NULL || _tcslen(cTimeStamp) == 0)) {int month, day, year, hours , minutes, seconds; 
		_stscanf_s(cTimeStamp,_T("%d-%d-%d %d:%d:%d"),&year, &month, &day, &hours, &minutes, &seconds); if(year == 1969) { // Epoch for CTime is 12/31/1969, but this doesn't work on all implemntations// of Windows so let's force it to the first date that always works.  If the // file reads that old then what's a few days for the sake of saving an assert.
			year = 1970;
			month = 1;
			day = 3;
		}if(year < 1970) {if(year < 70 && year > 38)
				year += 2000;else if(year > 70 && year < 1900)
				year += 1900;else
				year = cTime.GetYear();
		}// Fix for GMT of 0 where MSFT timezone check subtracts 3600 seconds.  This will // keep the CTime function from claiming an invalid parameter.  Bug is actually// in mktime()if(year == 1970 && month == 1 && day == 1)
			day = 3;
		cTime = CTime(year, month, day, hours, minutes, seconds); 
	}return cTime;
}

Tom


Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>