pushrbx icon

Timestamp

pushrbx | PRO | 09/02/13 04:01:18 PM UTC | 0 ⭐ | 450 👁️ | Never ⏰ | []
C |

540 B

|

None

|

0 👍

/

0 👎

typedef struct
{
    sgUInt year;
    sgUInt month;
    sgUInt day;
    sgBool correction;
} sgDate;
 
sgUShort GenTimeStamp(sgUShort year, sgUShort month, sgUShort day, sgBool correction)
{
    // Bits: YYYYYmmmmmDDDDDk
    return (sgUShort)((year << 11) | (month << 6) | (day << 1) | correction ? 1 & 0x1 : 0 & 0x1);
}
 
sgDate GetDateFromTimeStamp(sgUInt timestamp)
{
    sgDate date;
    date.year = (timestamp >> 11) & 0x1F;
    date.month = (timestamp >> 6) & 0x1F;
    date.day = (timestamp >> 1) & 0x1F;
    date.correction = timestamp & 0x1;
 
    return date;
}

Comments