LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   localtime and localtime_r (https://www.linuxquestions.org/questions/linux-newbie-8/localtime-and-localtime_r-4175463891/)

kanishka.dutta 05-29-2013 02:00 AM

localtime and localtime_r
 
I would like to know the difference between localtime and localtime_r

jdkaye 05-29-2013 02:18 AM

1. Open a terminal.
2. Type the following:
Code:

man localtime
3. Read what it says to the very end and you will have your answer.

jdk

evo2 05-29-2013 02:18 AM

Hi,

localtime_r() takes a second argument that has the return value. From the man page:
Code:

      The  localtime() function converts the calendar time timep to broken-down time repre‐
      sentation, expressed relative to the user's 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 nonzero 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.

Evo2.


All times are GMT -5. The time now is 06:26 PM.