Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between localtime() and gmtime() in C?

Tags:

c

time

I'm a newbie in C programming. Could anyone tell me what is/are the difference(s) between localtime() and gmtime() in C?

Thanks in avance!

like image 343
alwinlin Avatar asked Mar 23 '11 17:03

alwinlin


1 Answers

From "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  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.
like image 135
Corey Porter Avatar answered Sep 22 '22 11:09

Corey Porter