Advertisement
pushrbx

Timestamp

Sep 2nd, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. typedef struct
  2. {
  3.     sgUInt year;
  4.     sgUInt month;
  5.     sgUInt day;
  6.     sgBool correction;
  7. } sgDate;
  8.  
  9. sgUShort GenTimeStamp(sgUShort year, sgUShort month, sgUShort day, sgBool correction)
  10. {
  11.     // Bits: YYYYYmmmmmDDDDDk
  12.     return (sgUShort)((year << 11) | (month << 6) | (day << 1) | correction ? 1 & 0x1 : 0 & 0x1);
  13. }
  14.  
  15. sgDate GetDateFromTimeStamp(sgUInt timestamp)
  16. {
  17.     sgDate date;
  18.     date.year = (timestamp >> 11) & 0x1F;
  19.     date.month = (timestamp >> 6) & 0x1F;
  20.     date.day = (timestamp >> 1) & 0x1F;
  21.     date.correction = timestamp & 0x1;
  22.  
  23.     return date;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement