Question

I am trying to convert Datetime: http://msdn.microsoft.com/en-us/library/03ybds8y

to the number of seconds since 1970 using Visual C++.

I searched many solutions but could not make any of them work. Thanks

Was it helpful?

Solution

You can do this using a TimeSpan of the difference between the two dates. Something like this:

DateTime dtDateYouWantToConvert = /* .... */
DateTime dtReference(1970, 1, 1, 0, 0, 0);

TimeSpan tsDiff = dtDateYouWantToConvert - dtReference;

// calculate number of seconds (including fractional) since 1/1/1970
double dSeconds = tsDiff.TotalSeconds;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top