在DOS中,用4个字节表示年月日,时分秒,我怎么把这四个字节换算出来呢? 例如:2F 83 8B E1 表示2003年12月3号 17点16分01秒我改如何换算呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用一个 unsigned long 来表示时间可以从1900 起,如果你是在控制台下用VC6编程的话 ,可以使用 STL 库中的 time_t、tm struct 相关函数: mktime,time,ctime,gmtime,asctime 等time_t 就是一个 四字节的长整 把这四个字节赋值给一个long值或者time_t值,应该就是这样 主要是使用localtime函数#include <time.h>#include <stdio.h>void main( void ){ struct tm when; time_t now, result; int days; time( &now ); when = *localtime( &now ); printf( "Current time is %s\n", asctime( &when ) ); printf( "How many days to look ahead: " ); scanf( "%d", &days ); when.tm_mday = when.tm_mday + days; if( (result = mktime( &when )) != (time_t)-1 ) printf( "In %d days the time will be %s\n", days, asctime( &when ) ); else perror( "mktime failed" );} 我刚才看了一下2F 83 8B E1 这些数并不能组成一个正确的time_t值,我再看一看吧 0x3fcda9d1是time1(2003,12,3,17,16,1);的值,所以我真的不知道你是怎么转换的 int main(int argc, char* argv[]){// 2F 83 8B E1 表示2003年12月3号 17点16分01秒 FILETIME ft; SYSTEMTIME tm; DosDateTimeToFileTime(0x2f83 , 0x8be1 , &ft); FileTimeToSystemTime(&ft , &tm);}这个倒是可以转换一下,但是有问题,转换出来的时间是2003-12-3 17-21-02是不是搂主的数字有误;bluebohe(薄荷)的函数转换出来是多少? TO 薄荷: 是对的,具体算法是: 前两个字节表示年月日,日占五位,月占四位,年占7位,年是从1980开始的,就是1980加上前7个位的值; 后两个字节表示时分秒:秒占5个位,分占6位,时占5位,其中秒最小单位是2,既误差才2秒!你算算,我给的2F 83 89 E1 就是那个时间! 那又何必呢,有现在的高效函数调呀你是不是要在纯DOS下写这个程序呀? unsigned long ntime = 0x2F8389E1; unsigned long nDay,nYear,nMon,nH,nM,nS; nYear = ntime >> 25; nMon = (ntime >> 21) & 0xF; nDay = (ntime >> 16) & 0x1f; nH = (ntime >> 11) & 0x1f; nM = (ntime >> 5) & 0x3f; nS = ntime & 0x1f; CString strTime; strTime.Format("%04d-%02d-%02d %02d:%02d:%02d",nYear + 1980,nMon,nDay,nH,nM,nS); AfxMessageBox(strTime); 好象和你的时间,差一分钟 这样的内存操作居然不会错。 请问,如何控制OLEDB里的CSession.Open的Time Out? OpenGL实现实时图像数据采集问题???急急急急!!! IE->查看->工具栏 里面的地址栏的选中不选中状态在注册表哪里可以修改? 请假 谁有《高质量C。C++编程》这本书呀 一个关于数据类型问题请教!谢谢帮助! 请教把鼠标控制在一个区域中的方法 非模态对话框简单问题!在线等 MFC 打开Window自带的 计算器 一个小问题:不能进行类声明,哪位大侠有空,帮我看看程序(很简单的程序) 【散分】寻找2张光盘装的MSDN。2000年以前的那一版,有中文的。顶也有分~
time_t 就是一个 四字节的长整
#include <time.h>
#include <stdio.h>void main( void )
{
struct tm when;
time_t now, result;
int days; time( &now );
when = *localtime( &now );
printf( "Current time is %s\n", asctime( &when ) );
printf( "How many days to look ahead: " );
scanf( "%d", &days ); when.tm_mday = when.tm_mday + days;
if( (result = mktime( &when )) != (time_t)-1 )
printf( "In %d days the time will be %s\n",
days, asctime( &when ) );
else
perror( "mktime failed" );
}
int main(int argc, char* argv[])
{// 2F 83 8B E1 表示2003年12月3号 17点16分01秒 FILETIME ft;
SYSTEMTIME tm;
DosDateTimeToFileTime(0x2f83 , 0x8be1 , &ft);
FileTimeToSystemTime(&ft , &tm);
}这个倒是可以转换一下,但是有问题,转换出来的时间是2003-12-3 17-21-02
是不是搂主的数字有误;
bluebohe(薄荷)的函数转换出来是多少?
是对的,具体算法是:
前两个字节表示年月日,日占五位,月占四位,年占7位,年是从1980开始的,就是1980加上前7个位的值;
后两个字节表示时分秒:秒占5个位,分占6位,时占5位,其中秒最小单位是2,既误差才2秒!
你算算,我给的2F 83 89 E1 就是那个时间!
unsigned long nDay,nYear,nMon,nH,nM,nS;
nYear = ntime >> 25;
nMon = (ntime >> 21) & 0xF;
nDay = (ntime >> 16) & 0x1f;
nH = (ntime >> 11) & 0x1f;
nM = (ntime >> 5) & 0x3f;
nS = ntime & 0x1f;
CString strTime;
strTime.Format("%04d-%02d-%02d %02d:%02d:%02d",nYear + 1980,nMon,nDay,nH,nM,nS);
AfxMessageBox(strTime); 好象和你的时间,差一分钟