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");
    }

  • 相关阅读:
    hdu 4081 Qin Shi Huang's National Road System
    Finding Team Member
    hdu 5491 The Next
    Queue
    Backward Digit Sums
    HDU
    HDU
    CodeForces 500 A. New Year Transportation
    拓扑排序
    “玲珑杯”ACM比赛 Round #1 题解
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/5207483.html
Copyright © 2011-2022 走看看