tm time_t 转化的问题

szn_409 2016-01-24 08:26:35
tm tim1;
tim1.tm_year = 70;
tim1.tm_mon = 0;
tim1.tm_mday = 2;
tim1.tm_hour = 0;
tim1.tm_min = 0;
tim1.tm_sec = 0;

time_t time1;
time1 = mktime(&tim1);
为什么time1 为57600 而不是86400

话说如何得到1600年1月1号到现在的秒技术,有啥特殊方法么
...全文
206 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-01-25
  • 打赏
  • 举报
回复
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. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winbase.h. See Also Time Overview, Time Structures, CompareFileTime, GetFileTime, LARGE_INTEGER Time Functions The following functions are used with time. CompareFileTime DosDateTimeToFileTime FileTimeToDosDateTime FileTimeToLocalFileTime FileTimeToSystemTime GetFileTime GetLocalTime GetSystemTime GetSystemTimeAdjustment GetSystemTimeAsFileTime GetTickCount GetTimeZoneInformation LocalFileTimeToFileTime SetFileTime SetLocalTime SetSystemTime SetSystemTimeAdjustment SetTimeZoneInformation SystemTimeToFileTime SystemTimeToTzSpecificLocalTime
paschen 2016-01-25
  • 打赏
  • 举报
回复
因为和你时区有关
qq_33800727 2016-01-25
  • 打赏
  • 举报
回复
了解一下。。。。
赵4老师 2016-01-25
  • 打赏
  • 举报
回复
学习这些Windows Time相关的API的用法。
赵4老师 2016-01-25
  • 打赏
  • 举报
回复
或者参考这个:
#include <afxdisp.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, TCHAR* argv[]) {
    COleDateTime t;
    COleDateTimeSpan ts;
    CString s,fmt;
    int nYear;
    int nMonth;
    int nDay;
    int nHour;
    int nMin;
    int nSec;
    int lDays;
    int nHours;
    int nMins;
    int nSecs;
    int i,N;
    // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
        printf("Fatal Error: MFC initialization failed\n");
        return 1;
    }
    if (argc<13) {
        printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL|YYYY|YY}\n",argv[0]);
        return 2;
    }
    if (stricmp(argv[12],"SQL")==0) fmt="%Y-%m-%d %H:%M:%S";
    else if (stricmp(argv[12],"YYYY")==0) fmt="%Y%m%d %H%M%S";
    else if (stricmp(argv[12],"YY")==0) fmt="%y%m%d %H%M%S";
    else {
        printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL|YYYY|YY}\n",argv[0]);
        return 3;
    }
    nYear =atoi(argv[ 1]);
    nMonth=atoi(argv[ 2]);
    nDay  =atoi(argv[ 3]);
    nHour =atoi(argv[ 4]);
    nMin  =atoi(argv[ 5]);
    nSec  =atoi(argv[ 6]);
    lDays =atoi(argv[ 7]);
    nHours=atoi(argv[ 8]);
    nMins =atoi(argv[ 9]);
    nSecs =atoi(argv[10]);
    N     =atoi(argv[11]);
    if (N<=0) {
        printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL|YYYY|YY}\n",argv[0]);
        return 4;
    }
    t=COleDateTime( nYear, nMonth, nDay, nHour, nMin, nSec);
    ts=COleDateTimeSpan( lDays, nHours, nMins, nSecs );
    for (i=1;i<=N;i++) {
        s=t.Format(fmt);
        printf("%08d %s\n",i,s);
        t=t+ts;
    }
    return 0;
}
szn_409 2016-01-25
  • 打赏
  • 举报
回复
引用 1 楼 paschen 的回复:
返回的是从1970年1月1日的秒数 另外需要考虑一个问题,如果返回很早前到现在的秒数,在32位时(__time32_t)是否会溢出
是返回从1970年1月1日的秒计数,所以上述代码得到的应该是一天的秒计数为3600 * 24 = 86400, 请问为什么不是?
szn_409 2016-01-25
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
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. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winbase.h. See Also Time Overview, Time Structures, CompareFileTime, GetFileTime, LARGE_INTEGER Time Functions The following functions are used with time. CompareFileTime DosDateTimeToFileTime FileTimeToDosDateTime FileTimeToLocalFileTime FileTimeToSystemTime GetFileTime GetLocalTime GetSystemTime GetSystemTimeAdjustment GetSystemTimeAsFileTime GetTickCount GetTimeZoneInformation LocalFileTimeToFileTime SetFileTime SetLocalTime SetSystemTime SetSystemTimeAdjustment SetTimeZoneInformation SystemTimeToFileTime SystemTimeToTzSpecificLocalTime
老师你想说明啥?
paschen 2016-01-24
  • 打赏
  • 举报
回复
返回的是从1970年1月1日的秒数 另外需要考虑一个问题,如果返回很早前到现在的秒数,在32位时(__time32_t)是否会溢出

69,370

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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