zoukankan      html  css  js  c++  java
  • linux 中的gmtime和localtime函数

    一、 gmtime和localtime前后使用会有影响

    #include <stdio.h>
    #include <time.h>

    int main(int argc, char **argv)
    {
     time_t now;
     struct tm *tmutc, *tmlocal;

     /*获取日历时间*/
     time(&now);

     /*转换成tm时间*/
     tmutc = gmtime(&now);

     tmlocal = localtime(&now);


     /*输出时间*/
     printf("%s标准时间为:\t%s", tmutc->tm_zone, asctime(tmutc));
     
     printf("%s时间为:\t%s", tmlocal->tm_zone, asctime(tmlocal));

     return 0;
    }

    *******************************************

    CST标准时间为: Tue Jan 31 09:23:17 2012
    CST时间为:     Tue Jan 31 09:23:17 2012

    ******************************************

    二、 gmtime和localtime分开使用

    #include <stdio.h>
    #include <time.h>

    int main(int argc, char **argv)
    {
     time_t now;
     struct tm *tmutc, *tmlocal;

     /*获取日历时间*/
     time(&now);

     /*转换成tm时间*/
     tmutc = gmtime(&now); 

     /*输出时间*/
     printf("%s标准时间为:\t%s", tmutc->tm_zone, asctime(tmutc));

     tmlocal = localtime(&now);
     
     printf("%s时间为:\t%s", tmlocal->tm_zone, asctime(tmlocal));

     return 0;
    }

    *************************************************

    GMT标准时间为: Tue Jan 31 01:24:40 2012
    CST时间为:     Tue Jan 31 09:24:40 2012

    ************************************************

  • 相关阅读:
    UNIX常用shell
    exit函数
    linux消息队列
    互斥量
    RCS版本控制
    linux samba
    UML建模
    linux syslog
    python基础-列表List及内置方法
    仿美团详情页与购物车源码-详情页
  • 原文地址:https://www.cnblogs.com/Neddy/p/2332576.html
Copyright © 2011-2022 走看看