zoukankan      html  css  js  c++  java
  • C语言 常用的时间函数

    //时间函数的使用
    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    
    //time_t time(time_t *t);
    //如果t是空指针,直接返回当前时间。如果t不是空指针,返回当前时间的同时,将返回值赋予t指向的内存空间。
    
    //localtime()函数
    //说明:此函数获得的tm结构体的时间是日历时间。
    //用 法 : struct tm *localtime(const time_t *clock);
    //返回值:返回指向tm 结构体的指针.tm结构体是time.h中定义的用于分别存储时间的各个量(年月日等)的结构体.
    //gmtime()函数转换后的时间没有经过时区变换,是UTC时间(即格林威治时间) 。
    
    
    //asctime()函数
    //把timeptr指向的tm结构体中储存的时间转换为字符串字符串格式返格式为:回,Www Mmm dd hh:mm:ss yyyy。
    //其中Www为星期;Mmm为月份;dd为日;hh为时;mm为分;ss为秒;yyyy为年份。
    
    
    
    void main(){
        time_t timea;
        struct tm *t;
        timea = time(NULL);
        t = localtime(&timea);
        printf("Local Time is %s", asctime(t));
        system("pause");
    }

  • 相关阅读:
    20171017/20171018
    BZOJ[3193] [JLOI2013]地形生成
    BZOJ[1009] [HNOI2008]GT考试
    BZOJ[4767] 两双手
    BZOJ[4013] [HNOI2015]实验比较
    BZOJ[1925] [Sdoi2010]地精部落
    20171015 杂题
    20171015
    20171014
    USACO 2015 December Contest, Gold Problem 3. Bessie's Dream
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/5207483.html
Copyright © 2011-2022 走看看