精华内容
下载资源
问答
  • <div><ul><li>time_t overflows when it holds time of more than 127 years since epoch.</li><li>There is issue when converting time_t to struct tm.</li><li>We need to change TM_YEAR_BASE from 1900 to ...
  • 为什么tm_year是从1900开始而不是1970

    千次阅读 2019-04-04 22:33:42
    Why is the tm_year member in struct tm relative to 1900 rather than 1970 in C on macosx? 对该问题回答的原文: The struct tm is designed for parsing, displaying, and manipulating human-r...

    stackoverflow上找到了答案:

    Why is the tm_year member in struct tm relative to 1900 rather than 1970 in C on macosx?

    对该问题回答的原文:


    The struct tm is designed for parsing, displaying, and manipulating human-readable dates. When it was created, dates were commonly written and even stored without the “19” part of the year number and the Y2K problem was around 25 years away. So the convenience of making tm_year directly printable as two digits, by making it relative to 1900, apparently seemed reasonable at the time.


    大概意思就是说:


    struct tm用于解析,显示和操作人类可读的日期。 在创建日期时,日期通常是在年份去掉19”部分的情况下编写与存储,并且距离Y2K问题大约还有25年。 因此,相对于1900,将tm_year直接打印成两位数就十分便利,显然在当时是合理的。


    展开全文
  • c/c++ time->time_t->struct tm 中的tm_year 是从1900年算起的时间
    c/c++  time->time_t->struct tm 中的tm_year 是从1900年算起的时间
    
    展开全文
  • printf("%d-%d-%d %d:%d:%d\n",time->tm_year+1900,time->tm_mon+1,time->tm_mday,time->tm_hour,time->tm_min,time->tm_sec); } struct tm str2time(char * str){ struct tm *tmp_time = (struct tm *)malloc...
  • tm ,time_t,SYSTEMTIME转换

    千次阅读 2014-02-28 09:41:48
    time_t tmToTime_t(char * dt) { tm timeinfo; sscanf_s(dt, "%d-%d-%d %d:%d:%d", ...&timeinfo.tm_year, &timeinfo.tm_mon, &timeinfo.tm_mday, &timeinfo.tm_hour, &timeinfo.tm_min, &timeinfo.tm_sec); ti

    time_t tmToTime_t(char * dt)

    {

    tm timeinfo;
    sscanf_s(dt, "%d-%d-%d %d:%d:%d",
    &timeinfo.tm_year, &timeinfo.tm_mon, &timeinfo.tm_mday,
    &timeinfo.tm_hour, &timeinfo.tm_min, &timeinfo.tm_sec);
    timeinfo.tm_year -= 1900;
    timeinfo.tm_mon -= 1;       //month: 0-11  
    return  mktime(&timeinfo);

    }

    time_t SystemTimeToTime_t(const SYSTEMTIME& st)

    {
    tm temptm = { st.wSecond,
    st.wMinute,
    st.wHour,
    st.wDay,
    st.wMonth - 1,
    st.wYear - 1900,
    st.wDayOfWeek,
    0,
    0 };
    return mktime(&temptm);
    }


    SYSTEMTIME TimetToSystemTime(time_t t)
    {
    FILETIME ft;
    SYSTEMTIME pst;
    //LONGLONG nLL = Int32x32To64(t, 10000000) + 116444736000000000;  时间相差8小时
    LONGLONG nLL = Int32x32To64(t, 10000000) + 116445024000000000;


    ft.dwLowDateTime = (DWORD) nLL;
    ft.dwHighDateTime = (DWORD) (nLL >> 32);
    FileTimeToSystemTime(&ft, &pst);
    return pst;
    }
    展开全文
  • 1. tm结构体 struct tm { int tm_sec; /*秒,正常范围0-59, 但允许至61*/ int tm_min; /*分钟,0-59*/ int tm_hour; /*小时, 0-23*/ ... int tm_year; /*年, 从1900至今已经多少年*/ 1900+

    1. tm结构体

    struct tm
    {
        int tm_sec;  /*秒,正常范围0-59, 但允许至61*/
        int tm_min;  /*分钟,0-59*/
        int tm_hour; /*小时, 0-23*/
        int tm_mday; /*日,即一个月中的第几天,1-31*/
        int tm_mon;  /*月, 从一月算起,0-11*/  1+p->tm_mon;
        int tm_year;  /*年, 从1900至今已经多少年*/  1900+ p->tm_year;
        int tm_wday; /*星期,一周中的第几天, 从星期日算起,0-6*/
        int tm_yday; /*从今年1月1日到目前的天数,范围0-365*/
        int tm_isdst; /*日光节约时间的旗标*/
    };
    

    2.time_t

    包含文件:<time.h>,实质为长整型。

    #ifndef __TIME_T
    #define __TIME_T     /* 避免重复定义 time_t */
    typedef long     time_t;    /* 时间值time_t 为长整型的别名*/
    #endif

    3. mktime()函数

    函数原型:

    time_t mktime(struct tm *timeptr);

    函数说明

    mktime()用来将参数timeptr所指的tm结构数据转换成从公元1970年1月1日0时0分0秒算起至今的UTC时间所经过的秒数。

    返回值

    该函数返回一个 time_t 值,该值对应于以参数传递的日历时间。如果发生错误,则返回 -1 值。

    示例1:

    #include 
    #include 
    main()
    {
        time_t timep;
        strcut tm *p;
        time(&timep);
        printf("time() : %d \n",timep);
        p=localtime(&timep);
        timep = mktime(p);
        printf("time()->localtime()->mktime():%d\n",timep);
        //获取时间差
         struct tm tnNormal;
        time_t tNormal;
        tNormal.year = 2010-1900;
        tNormal.tm_mon= 1-1;
        tNormal.tm_mday=1;
        tNormal.tm_hour=0;
        tNormal.tm_min=0;
        tNormal.tm_sec=0;
        tNormal.tm_isdst=0;
        tNormal =mktime(&tmNormal);
        time_t tcur = time(0);
        long defferent = difftime(tcur,tNormal);
    }
    执行
    time():974943297
    time()->localtime()->mktime():974943297

     

    示例:

    /* 输入日期判断是周几 */
    #include <stdio.h>      /* printf, scanf */
    #include <time.h>       /* time_t, struct tm, time, mktime */
     
    int main ()
    {
        time_t rawtime;
        struct tm * timeinfo;
        int year, month ,day;
        const char * weekday[] = { "周日", "周一","周二", "周三","周四", "周五", "周六"};
     
        /* 用户输入日期 */
        printf ("年: "); fflush(stdout); scanf ("%d",&year);
        printf ("月: "); fflush(stdout); scanf ("%d",&month);
        printf ("日: "); fflush(stdout); scanf ("%d",&day);
     
        /* 获取当前时间信息,并修改用户输入的输入信息 */
        time ( &rawtime );
        timeinfo = localtime ( &rawtime );
        timeinfo->tm_year = year - 1900;
        timeinfo->tm_mon = month - 1;
        timeinfo->tm_mday = day;
     
        /* 调用 mktime: timeinfo->tm_wday  */
        mktime ( timeinfo );
     
        printf ("那一天是:%s\n", weekday[timeinfo->tm_wday]);
     
        return 0;
    }
    
    运行结果
    年: 2018
    月: 7
    日: 26
    那一天是:周四

    4.time函数

    描述

    C 库函数 time_t time(time_t *seconds) 返回自纪元 Epoch(1970-01-01 00:00:00 UTC)起经过的时间,以秒为单位。如果 seconds 不为空,则返回值也存储在变量 seconds 中。

    函数定义

    time_t time(time_t *seconds)

    参数

    seconds -- 这是指向类型为 time_t 的对象的指针,用来存储 seconds 的值。

    返回值

    以 time_t 对象返回当前日历时间。

    示例:

    #include <stdio.h>
    #include <time.h>
     
    int main ()
    {
      time_t seconds;
     
      seconds = time(NULL);
      printf("自 1970-01-01 起的小时数 = %ld\n", seconds/3600);
      
      return(0);
    }
    
    运行结果
    自 1970-01-01 起的小时数 = 373711

     

    展开全文
  • struct tm转time_t

    千次阅读 2013-07-12 23:56:50
    int status = luaL_dofile(L,"setting.ini"); if (!status) { struct tm dt; ...lua_getglobal(L, "year");dt.tm_year=lua_tointeger(L,-1); lua_getglobal(L, "mon");dt.tm_mon=lua_tointeger(L,-1); lua_ge
  • tm, time_t 转换

    2011-08-22 13:33:00
    tm, time_t 转换 //tm->time_t struct tm tmDate; time_t time_tDate; memset(&tmDate,0,sizeof(tm));... tmDate.tm_year -= 1900; //需要减去1900,否则mktime会返回-1 tmDate.tm_mon -=1; ...
  • ''' 标准库: 1.time 时间的三种表示方法:a:时间戳(timestamp) b:格式化的时间字符串 c:... time.struct_time(tm_year=2018, tm_mon=2, tm_mday=7, tm_hour=22, tm_min=28, tm_sec=9, tm_wday=2, tm_yday=38...
  • printf("%d-%02d-%02d ",(p->tm_year), (p->tm_mon),p->tm_mday); printf("%02d:%02d:%02d\n", p->tm_hour, p->tm_min, p->tm_sec); t = t+20; testTime(&t,p); printf("%d-%02d-%02d ",(p->tm_year), (p-...
  • import time date = time.localtime() ...#time.struct_time(tm_year=2018, tm_mon=2, tm_mday=24, tm_hour=19, tm_min=42, tm_sec=57, tm_wday=5, tm_yday=55, tm_isdst=0) year = date[0]...
  • __time64_t 转 systemtime

    千次阅读 2013-12-03 10:31:39
    SYSTEMTIME OnTime64toSystemTime(__time64_t& itime) { struct tm *temptm = _localtime64(&itime)...SYSTEMTIME st = {1900 + temptm->tm_year,  1 + temptm->tm_mon,  temptm->tm_wday,  temptm->tm_mday, 
  • 时间模块_技巧

    2018-12-18 20:52:26
    print(time.localtime(time.time()...time.struct_time(tm_year=2018, tm_mon=10, tm_mday=23, tm_hour=19, tm_min=4, tm_sec=39, tm_wday=1, tm_yday=296, tm_isdst=0) print(time.asctime(time.localtime(time.tim...
  • python_时间模块

    2020-05-12 10:49:05
    ### time模块 time可以提供的时间格式有以下三种: import time # 时间戳时间 print(time.time()) 1589166745.950339 # 结构化时间,这个跟元组长得很像,叫做时间对象 ...time.struct_time(tm_year=2020, tm_mon=5
  • python_time模块

    2017-07-16 14:45:00
    time 模块 import time import datetime ''' 打印结果1500186750.494887 ...打印结果time.struct_time(tm_year=2017, tm_mon=7, tm_mday=16, tm_hour=6, tm_min=32, tm_sec=30, tm_wday=6, tm_yday
  • <div><p>Hi there and thank you for providing open-watcom....tm_year + 1900 ); </code></pre> <p>Many Thanks, <p>Andreas</p><p>该提问来源于开源项目:open-watcom/open-watcom-v2</p></div>
  • 编程库1.timeimport timeprint(time.time())time = time.localtime( time.time() )print(time)print(time.tm_year)"""1563803665.310865time.struct_time(tm_year=2019, tm_mon=7, tm_mday=22, tm_hour=21, tm_min=...
  • python_模块

    2018-03-18 20:36:00
    time 1 time_obj = time.localtime() ... 2 print("%s-%s-%s %s:%s" % (time_obj.tm_year,time_obj.tm_mon,time_obj.tm_mday,time_obj.tm_hour,time_obj.tm_min)) 3 4 print(time.strftime("%Y-%m-%d %H:...
  • python 时间有四种表达,时间元组,...//时间元组import timetime.localtime()//time.struct_time(tm_year=2019, tm_mon=7, tm_mday=16, tm_hour=18, tm_min=40, tm_sec=33, tm_wday=1, tm_yday=197, tm_isdst=0)//...
  • Python的Time模块是关于时间的,获取当前时间、时间格式化等。time是原生安装时就有的,不需要进行安装...(tm_year=2017, tm_mon=10, tm_mday=11, tm_hour=7, tm_min=45, tm_sec=6, tm_wday=2, tm_yday=284, tm_isdst=0
  • time.localtime():返回一个对象结构化时间time.struct_time(tm_year=2020, tm_mon=8, tm_mday=5, tm_hour=16, tm_min=55, tm_sec=6, tm_wday=2, tm_yday=218, tm_isdst=0) time.localtime().tm_year:可以获取单个...
  • time模块方法:time.time():获取...不给参数的话就会默认将time.time()作为参数传入time.localtime():索引属性含义0tm_year年1tm_mon月2tm_mday日3tm_hour时4tm_min分5tm_sec秒6tm_wday一周中的第几天7tm_yday一年中...
  • c++ tm结构体和time_t时间戳的转换

    千次阅读 2018-04-11 19:54:37
    贴一段简单的代码#include &lt;time.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main() { struct tm t1,t2; //结构体 ...t1.tm_year,&amp;t1.tm_mo...
  • linux__时间__操作

    2012-05-19 10:48:07
    sno_guo的博客,用来记录平时用到的一些小函数.不断更新中........unsigned int get_current_time() { time_t timep; struct tm *p; int year; time(&timep); p=localtime(&timep);... year=(int)(p->tm_year-
  • cert_desc_test.py is failing

    2020-12-04 11:46:17
    AssertionError: time.struct_time(tm_year=2013, tm_mon=5, tm_mday=22, tm_hour=23, tm_min=49, tm_sec=4, tm_wday=2, tm_yday=142, tm_isdst=0) != time.struct_time(tm...
  • Python常用时间模块讲解一、常用的时间格式1....2.结构化时间格式,例如:t=time.struct_time(tm_year=2018,tm_mon=4,tm_mday=8,tm_hour=22,tm_min=22,tm_sec=4,tm_wday=6,tm_yday=98, tm_isdst=0),里面包含年、月...
  • time.struct_time 结构0tm_year(for example, 1993)(下注)1tm_monrange [1, 12](下注)2tm_mdayrange [1, 31]3tm_hourrange [0, 23]4tm_minrange [0, 59]5tm_secrange [0, 61](下注)6tm_wdayrange [0, 6], Monday is ...
  • 大家都是着急下班的 程序员,何必写一大堆理论来装逼浪费时间呢? 早点复制 过去 早点下班不香嘛? 使用方法如下: char cNow[32] = { 0 };... time_t now = time(NULL);...tm_year + 1900, pNow->tm_mon + 1, pNo
  • python有两个重要的时间模块,分别是time和datetimetime模块表示时间的几种方法时间元组time.struct_time(tm_year=2016, tm_mon=7, tm_mday=21,tm_hour=22, tm_min=32, tm_sec=51,tm_wday=3, tm_yday=203, tm_isdst=...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,346
精华内容 538
关键字:

tm_year