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号到现在的秒技术,有啥特殊方法么
...全文
267 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)是否会溢出
内容概要:本文针对无刷直流电机驱动的电子机械制动(EMB)执行器,建立了考虑Stribeck摩擦特性的非线性耦合动力学模型,并在Simulink环境中完成了系统级仿真分析。研究综合集成了电机动力学、齿轮传动机构与制动执行机构的动力学特性,构建了高保真的机电一体化系统模型。重点引入Stribeck摩擦模型以精确描述低速工况下执行器内部存在的静摩擦、粘滞摩擦与库仑摩擦之间的过渡行为,有效提升了系统在启停、反向运动等瞬态过程中的动态响应仿真精度。通过多工况仿真验证了模型的有效性,能够准确反映摩擦引起的爬行、滞后与定位误差等非线性现象,为EMB系统的高性能控制算法设计(如摩擦补偿、滑模控制)与结构优化提供了高可信度的仿真平台。; 适合人群:从事汽车电子制动系统、电机驱动控制、机电系统建模与仿真研究的研究生、科研人员及工程技术人员,需具备扎实的机械动力学、自动控制理论基础和MATLAB/Simulink仿真能力。; 使用场景及目标:①用于高精度电子机械制动系统的设计验证与性能预测;②为消除摩擦非线性影响的先进控制策略(如自适应控制、智能控制)提供精确的被控对象模型;③深入探究Stribeck摩擦等非线性因素对系统动态性能(如响应延迟、稳态误差)的作用机理; 阅读建议:读者应结合提供的Simulink模型文件,深入剖析Stribeck摩擦模块的数学实现与参数辨识方法,建议通过改变输入指令(如阶跃、正弦)和负载条件进行对比仿真,以直观理解非线性摩擦对系统动态特性的影响。

70,038

社区成员

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

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