UC 文件系统

阅读更多
#include 
#include 

#define HEX2BCD(x) (((x) % 10) + ((((x) / 10) % 10) << 4))  /*20 -> 20H*/
#define UINT8 unsigned char

/*
    功能:获取BCD时间
    out:    [out]    保存获取到的BCD时间,格式为:秒分时日月年(各占一字节,BCD格式)
*/
void getBCDTime(UINT8 *out)
{
    time_t t;
    int i = 0;
    struct tm *whj = NULL;

    t = time(NULL);
    whj = localtime(&t);
    out[i++] = HEX2BCD(whj -> tm_sec);
    out[i++] = HEX2BCD(whj -> tm_min);
    out[i++] = HEX2BCD(whj -> tm_hour);
    out[i++] = HEX2BCD(whj -> tm_mday);
    out[i++] = HEX2BCD(whj -> tm_mon+1);
    out[i++] = HEX2BCD(whj -> tm_year-100);
}

int main()
{
    UINT8 out[6] = {0};
    int i = 0;
    getBCDTime(out);

    while(i < 6)
    {
        printf("%.2X ", out[i++]);
    }
    printf("\n");

    return 0;
}

你可能感兴趣的:(系统时间)