zoukankan      html  css  js  c++  java
  • 关于c语言中时间函数的一些归纳

    头文件#include <time.h>

    概述:
    ctime(),gmtime(),localtime()函数都带有一个代表日历时间的time_t类型的参数。当要描述为一个绝对的值时,它代表从新纪元(1970年1月1日凌晨)开始到现在所流逝的秒数。
    asctime()和mktime()函数带有一个参数代表修正时间(分解时间),这是一个代表值分解成年、月、日等等。
    休正时间(broken-down time)被存储在结构体tm中,这个结构体定义在<time.h>中。
    结构体如下:
    struct tm {
                   int tm_sec;         /* seconds */
                   int tm_min;         /* minutes */
                   int tm_hour;        /* hours */
                   int tm_mday;        /* day of the month */
                   int tm_mon;         /* month */
                   int tm_year;        /* year */
                   int tm_wday;        /* day of the week */
                   int tm_yday;        /* day in the year */
                   int tm_isdst;       /* daylight saving time */
               };

    char *ctime(const time_t *timep);
    ctime() 等于asctime(localtime(t)).它将日历时间t转换为零终止字符串,字符串类型如下:“Wed Jun 30 21:49:08 1993 ”

    struct tm *gmtime(const time_t *timep);
    gmtime()函数转换日历时间为分解时间。格林尼治时间

    struct tm *localtime(const time_t *timep);
    localtime()函数转换日历时间为分解时间。当地时间

    char *asctime(const struct tm *tm);
    asctime()函数转换分解时间为零终止字符串(同ctime())

    time_t mktime(struct tm *tm);
    mktime()函数转换分解时间结构体(表示为当地时间)为日历时间。
    举例:
    #include <stdio.h>
    #include <time.h>

    int main(int argc, const char *argv[])
    {
         time_t biggest = 0x7fffffff;
         time_t result;

         result = time(NULL);
         printf("%s",asctime(localtime(&result)));//当地现在时间
         printf("biggest = %s",ctime(&biggest));//给出最大的当地最大时间

         return 0;
    }

    输出:
    Thu Nov 21 12:15:49 2013
    biggest = Tue Jan 19 11:14:07 2038
  • 相关阅读:
    二逼平衡树(树套树)
    NOI2010 超级钢琴
    SDOI2011 消耗战
    HNOI2013 游走
    [SDOI2010]外星千足虫
    [UVA 11374]Airport Express
    [Luogu P1354]房间最短路问题
    [Luogu P2296][NOIP 2014]寻找道路
    高精度算法
    洛谷红名+AC150祭
  • 原文地址:https://www.cnblogs.com/vonyao/p/3614333.html
Copyright © 2011-2022 走看看