zoukankan      html  css  js  c++  java
  • 时间编程,王明学learn

                        时间编程

    一、时间类型

      Coordinated Universal Time(UTC):世界标准时间,也就是大家所熟知的格林威治标准时间(Greenwich Mean Time,GMT)

      Calendar Time:日历时间,是用“从一个标准时间点(如:1970年1月1日0点)到此时经过的秒数”来表示的时间。

    二、函数学习

    2.1获取日历时间time

    2.1.2 函数原形

      time_t time(time_t* t);

    2.1.3 函数功能

      返回日历时间

    2.1.4 所属头文件

      <time.h>

    2.1.5 返回值

      成功:返回的是日历时间

         失败: -1

    2.1.6 参数说明

      t:如果t指针不为空则用来保存返回的时间

    2.2获取格林威治时间gmtime

    2.2.1 函数原形

      struct tm* gmtime(const time_t* timep);

    2.2.2 函数功能

      把参数timp所指的日历时间转换成世界标准时间(格林威治时间);

    2.2.3 所属头文件

      <time.h>

    2.2.4 返回值

      成功:返回世界标准时间以struct tm形式存储

    2.2.5 参数说明

      timep:待转化的日历时间

    2.3获取本地时间localtime

    2.3.1 函数原形

      struct tm* localtime(const time_t* timep);

    2.3.2函数功能

      将参数timep指向的日历时间转换为当地时间

    2.3.3 所属头文件

      <time.h>

    2.3.4 返回值

      成功:返回以struct tm格式存储的本地时间

         失败:返回NULL

    2.3.5 参数说明

      timep:指向待转化的日历时间

    2.4以字符串方式显示时间asctime

    2.4.1 函数原形

      char* asctime(const struct tm* tm);

    2.4.2 函数功能

      将tm格式存储的时间转换为字符串

    2.4.3 所属头文件

      <time.h>

    2.4.4 返回值

      成功:字符串方式显示的时间

    2.4.5 参数说明

      待转化的tm格式的时间

    2.5 获取高精度时间gettimeofday

    2.5.1 函数原形

      int gettimeofday(struct timeval* tv,struct timezon* tzone);

    2.5.2 函数功能

      获取高进度的时间

    2.5.3 所属头文件

      <sys/time.h>

    2.5.4 返回值

      成功: 0

         失败:-1

    2.5.5 参数说明

      tv:保存从1970年1月1日0:0:0到现在所经历的秒数和微妙数

      tzone:通常设置为NULL

     

     

  • 相关阅读:
    LeetCode 485. Max Consecutive Ones
    LeetCode 367. Valid Perfect Square
    LeetCode 375. Guess Number Higher or Lower II
    LeetCode 374. Guess Number Higher or Lower
    LeetCode Word Pattern II
    LeetCode Arranging Coins
    LeetCode 422. Valid Word Square
    Session 共享
    java NIO
    非阻塞IO
  • 原文地址:https://www.cnblogs.com/wmx-learn/p/5302114.html
Copyright © 2011-2022 走看看