首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

简单有关问题,获取系统日期,然后做个转换。多谢

2012-04-17 
简单问题,获取系统日期,然后做个转换。谢谢。请教一下,获得系统日期 ,然后转换成十六进制的BYTE类型。例如:系

简单问题,获取系统日期,然后做个转换。谢谢。
请教一下,
获得系统日期 ,然后转换成十六进制的BYTE类型。
例如:系统日期为 2011年6月15日。
转换为
BYTE date[8]= { 0x02,0x00,0x01,0x01,
  0x00,0x06,0x01,0x05,}


大家给指导指导啊。给个代码吧,非常感谢啊。

[解决办法]
用字符串来转比较好

C/C++ code
CTime time = CTime::GetCurrentTime();    CString strText;    strText.Format(_T("%04d%02d%02d"), time.GetYear(), time.GetMonth(), time.GetDay());    int len = strText.GetLength();    BYTE* pData = new BYTE[len];    memset(pData, 0, len * sizeof(BYTE));    for(int i=0; i<len; i++)    {        pData[i] = strText[i] - 0x30;    }    CString str;    CString tmp;    for(int i=0; i<len; i++)    {        tmp.Format(_T("0x%02x, "), pData[i]);        str += tmp;    }    AfxMessageBox(str);
[解决办法]
SYSTEMTIME *systime = new SYSTEMTIME;
GetLocalTime(systime);
int years ; 
int months ;
int days ;
int hours ;
int minutes ;
int seconds ;
int milliseconds ;
years = systime->wYear ; 
months = systime->wMonth ; 
days = systime->wDay ;
hours = systime->wHour ;
minutes = systime->wMinute ;
seconds = systime->wSecond ;
milliseconds = systime->wMilliseconds ;

delete systime ;
systime = NULL ;

CString str_time ;
str_time.Format("%d-%d-%d %d:%d:%d:%d" , 
years ,months ,days ,hours ,minutes ,seconds ,milliseconds);

热点排行