【问题标题】:what's the difference between localtime() and gmtime() in C?C语言中的localtime()和gmtime()有什么区别?
【发布时间】:2011-07-21 12:13:55
【问题描述】:

我是 C 编程的新手。谁能告诉我 C 语言中 localtime() 和 gmtime() 之间的区别是什么?

提前感谢!

【问题讨论】:

  • 你了解什么是时区吗?
  • 我喜欢time and date dot com,因为我必须应对全球各地的时间。

标签: c time


【解决方案1】:

来自“本地时间”:

   The  gmtime()  function converts the calendar time timep to broken-down
   time representation, expressed in Coordinated Universal Time (UTC).  It
   may return NULL when the year does not fit into an integer.  The return
   value points to a statically allocated struct which might be  overwrit‐
   ten  by  subsequent  calls  to any of the date and time functions.  The
   gmtime_r() function does the same, but stores the data in  a  user-sup‐
   plied struct.

   The  localtime()  function  converts the calendar time timep to broken-
   time representation, expressed relative to the user’s  specified  time‐
   zone.  The function acts as if it called tzset(3) and sets the external
   variables tzname with information about the current timezone,  timezone
   with  the difference between Coordinated Universal Time (UTC) and local
   standard time in seconds, and daylight to a non-zero value if  daylight
   savings  time  rules  apply  during  some part of the year.  The return
   value points to a statically allocated struct which might be  overwrit‐
   ten  by  subsequent  calls  to any of the date and time functions.  The
   localtime_r() function does the same, but stores the data  in  a  user-
   supplied struct.  It need not set tzname, timezone, and daylight.

【讨论】:

    【解决方案2】:

    gmtime 采用协调世界时 (UTC),而 localtime 采用您的时区

    【讨论】:

      猜你喜欢
      • 2015-04-30
      • 1970-01-01
      • 2017-01-09
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      相关资源
      最近更新 更多