سؤال

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

هل كانت مفيدة؟

المحلول

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;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top