在C语言中,localtime()和gmtime()有什么区别?

11

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

提前致谢!


3
你了解时区是什么吗? - Adrien Plisson
当我需要处理全球时间时,我喜欢使用time and date dot com - pmg
2个回答

14

来自 "man localtime":

   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  overwritten  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-supplied struct.

   The  localtime()  function  converts the calendar time timep to broken-
   time representation, expressed relative to the users  specified  timezone.  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  overwritten  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.

8

gmtime以协调世界时(UTC)为准,localtime以你所在的时区为准。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接