Unix时间戳到FAT时间戳 [英] Unix timestamp to FAT timestamp

查看:230
本文介绍了Unix时间戳到FAT时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将时间结构转换为FAT时间戳。我的代码看起来像:

Im trying to convert a time structure to a FAT timestamp. My code looks like:

unsigned long Fat(tm_struct pTime)
{
    unsigned long FatTime = 0;

    FatTime |= (pTime.seconds / 2) >> 1;
    FatTime |= (pTime.minutes) << 5;
    FatTime |= (pTime.hours) << 11;
    FatTime |= (pTime.days) << 16;
    FatTime |= (pTime.months) << 21;
    FatTime |= (pTime.years + 20) << 25;

    return FatTime;
}

有人是否有正确的代码?

Does someone have the correct code?

推荐答案

The DOS date/time format is a bitmask:

               24                16                 8                 0
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
|Y|Y|Y|Y|Y|Y|Y|M| |M|M|M|D|D|D|D|D| |h|h|h|h|h|m|m|m| |m|m|m|s|s|s|s|s|
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
 \___________/\________/\_________/ \________/\____________/\_________/
    year        month       day      hour       minute        second

The year is stored as an offset from 1980. 
Seconds are stored in two-second increments. 
(So if the "second" value is 15, it actually represents 30 seconds.)

我不知道你正在使用的tm_struct,但如果它是 http://www.cplusplus.com/参考/ ctime / tm / 然后

I dont know the tm_struct you are using but if it's http://www.cplusplus.com/reference/ctime/tm/ then

unsigned long FatTime = ((pTime.tm_year - 80) << 25) | 
                        (pTime.tm_mon << 21) |
                        (pTime.tm_mday << 16) |
                        (pTime.tm_hour << 11) |
                        (pTime.tm_min << 5) |
                        (pTime.tm_sec >> 1);

这篇关于Unix时间戳到FAT时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆