code_junkie

Convert System::DateTime to _timeb

Nov 13th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. struct _timeb {
  2. long time; // 4 bytes
  3. unsigned short millitm; // 2 bytes
  4. short timezone; // 2 bytes
  5. short dstflag; // 2 bytes
  6. };
  7.  
  8. DateTime dateTime = DateTime::UtcNow;
  9. DateTime baseTime(1970, 1, 1, 0, 0, 0, DateTimeKind::Utc);
  10. TimeSpan delta = dateTime - baseTime;
  11.  
  12. _timeb timestamp;
  13. timestamp.time = delta.TotalSeconds;
  14. timestamp.millitm = dateTime.Millisecond;
  15. timestamp.dstflag = TimeZoneInfo::Local->IsDaylightSavingTime(dateTime) ? 1 : 0;
  16. timestamp.timezone = TimeZoneInfo::Local->BaseUtcOffset.TotalMinutes * -1;
Add Comment
Please, Sign In to add comment