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

cy2800 2013-08-28 04:32:59
如题,1970-01-01到现在的毫秒数据的4字节十六进制表示。
求高人指点。
...全文
280 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿先森 2013-11-01
  • 打赏
  • 举报
回复
http://download.csdn.net/detail/allenemo/6487471
赵4老师 2013-08-29
  • 打赏
  • 举报
回复
秒和毫秒不是一回事!
赵4老师 2013-08-29
  • 打赏
  • 举报
回复
time Gets the system time. time_t time( time_t *timer ); Routine Required Header Compatibility time <time.h> ANSI, Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value time returns the time in elapsed seconds. There is no error return. Parameter timer Storage location for time Remarks The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time, according to the system clock. The return value is stored in the location given by timer. This parameter may be NULL, in which case the return value is not stored. Example /* TIMES.C illustrates various time and date functions including: * time _ftime ctime asctime * localtime gmtime mktime _tzset * _strtime _strdate strftime * * Also the global variable: * _tzname */ #include <time.h> #include <stdio.h> #include <sys/types.h> #include <sys/timeb.h> #include <string.h> void main() { char tmpbuf[128], ampm[] = "AM"; time_t ltime; struct _timeb tstruct; struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 }; /* Set time zone from TZ environment variable. If TZ is not set, * the operating system is queried to obtain the default value * for the variable. */ _tzset(); /* Display operating system-style date and time. */ _strtime( tmpbuf ); printf( "OS time:\t\t\t\t%s\n", tmpbuf ); _strdate( tmpbuf ); printf( "OS date:\t\t\t\t%s\n", tmpbuf ); /* Get UNIX-style time and display as number and string. */ time( <ime ); printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime ); printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) ); /* Display UTC. */ gmt = gmtime( <ime ); printf( "Coordinated universal time:\t\t%s", asctime( gmt ) ); /* Convert to time structure and adjust for PM if necessary. */ today = localtime( <ime ); if( today->tm_hour > 12 ) { strcpy( ampm, "PM" ); today->tm_hour -= 12; } if( today->tm_hour == 0 ) /* Adjust if midnight hour. */ today->tm_hour = 12; /* Note how pointer addition is used to skip the first 11 * characters and printf is used to trim off terminating * characters. */ printf( "12-hour time:\t\t\t\t%.8s %s\n", asctime( today ) + 11, ampm ); /* Print additional time information. */ _ftime( &tstruct ); printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm ); printf( "Zone difference in seconds from UTC:\t%u\n", tstruct.timezone ); printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] ); printf( "Daylight savings:\t\t\t%s\n", tstruct.dstflag ? "YES" : "NO" ); /* Make time for noon on Christmas, 1993. */ if( mktime( &xmas ) != (time_t)-1 ) printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) ); /* Use time structure to build a customized time string. */ today = localtime( <ime ); /* Use strftime to build a customized time string. */ strftime( tmpbuf, 128, "Today is %A, day %d of %B in the year %Y.\n", today ); printf( tmpbuf ); } Output OS time: 21:51:03 OS date: 05/03/94 Time in seconds since UTC 1/1/70: 768027063 UNIX time and date: Tue May 03 21:51:03 1994 Coordinated universal time: Wed May 04 04:51:03 1994 12-hour time: 09:51:03 PM Plus milliseconds: 279 Zone difference in seconds from UTC: 480 Time zone name: Daylight savings: YES Christmas Sat Dec 25 12:00:00 1993 Today is Tuesday, day 03 of May in the year 1994. Time Management Routines See Also asctime, _ftime, gmtime, localtime, _utime
signforlin 2013-08-28
  • 打赏
  • 举报
回复
引用 2 楼 max_min_ 的回复:

#include <time.h>
#include <stdio.h>
    
    unsigned long sec = time(NULL); 
    //c 
    printf(" %lx\n", sec); 
    //c++
    cout << hex << sec << endl;
+1 楼主要是想每个数字单独取16进制,加个char数组,稍微变下就行。
赵4老师 2013-08-28
  • 打赏
  • 举报
回复
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.
max_min_ 2013-08-28
  • 打赏
  • 举报
回复

#include <time.h>
#include <stdio.h>
    
    unsigned long sec = time(NULL); 
    //c 
    printf(" %lx\n", sec); 
    //c++
    cout << hex << sec << endl;
woshinia 2013-08-28
  • 打赏
  • 举报
回复
long ltime;
	_time32(<ime);
	printf("%x",ltime);

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧