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

C++ 当前时间毫秒数变换为4字节十六进制

2013-09-05 
C++ 当前时间毫秒数转换为4字节十六进制如题,1970-01-01到现在的毫秒数据的4字节十六进制表示。求高人指点。

C++ 当前时间毫秒数转换为4字节十六进制
如题,1970-01-01到现在的毫秒数据的4字节十六进制表示。
求高人指点。
[解决办法]

long ltime;
_time32(&ltime);
printf("%x",ltime);

[解决办法]

#include <time.h>
#include <stdio.h>
    
    unsigned long sec = time(NULL); 
    //c 
    printf(" %lx\n", sec); 
    //c++
    cout << hex << sec << endl;

[解决办法]
GetSystemTime
The GetSystemTime function retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC). 

VOID GetSystemTime(
  LPSYSTEMTIME lpSystemTime   // address of system time structure
);
 
Parameters
lpSystemTime 
Pointer to a SYSTEMTIME structure to receive the current system date and time. 
Return Values
This function does not return a value. 


SystemTimeToFileTime
The SystemTimeToFileTime function converts a system time to a file time. 

BOOL SystemTimeToFileTime(
  CONST SYSTEMTIME *lpSystemTime,
                          // address of system time to convert
  LPFILETIME lpFileTime   // address of buffer for converted file 
                          // time
);
 
Parameters
lpSystemTime 
Pointer to a SYSTEMTIME structure that contains the time to be converted. 


The wDayOfWeek member of the SYSTEMTIME structure is ignored. 

lpFileTime 
Pointer to a FILETIME structure to receive the converted system time. 
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError. 

FILETIME
The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601. 

typedef struct _FILETIME { // ft 
    DWORD dwLowDateTime; 
    DWORD dwHighDateTime; 
} FILETIME; 
 
Members
dwLowDateTime 
Specifies the low-order 32 bits of the file time. 
dwHighDateTime 
Specifies the high-order 32 bits of the file time. 
Remarks
It is not recommended that you add and subtract values from the FILETIME structure to obtain relative times. Instead, you should 

Copy the resulting FILETIME structure to a LARGE_INTEGER structure. 
Use normal 64-bit arithmetic on the LARGE_INTEGER value. 

[解决办法]

引用:

#include <time.h>
#include <stdio.h>
    
    unsigned long sec = time(NULL); 
    //c 
    printf(" %lx\n", sec); 
    //c++
    cout << hex << sec << endl;

+1

楼主要是想每个数字单独取16进制,加个char数组,稍微变下就行。

热点排行