Arya
Arya

Reputation: 371

Behaviour of library call localtime() on different Linux platforms

I want to know if localtime works differently on different platforms if timezone is set same in both. If it does,what are dependent parameters other than timezone?

I run this in 2 platforms:

#include <stdio.h>
#include <time.h>
#include <unistd.h>

int main()
{
    time_t t,t1;//,result;
    double d1;
    struct tm *tm;
    t1 = 1384496356;

    tm = localtime(&t1);

    printf("tm->tm_hour %d tm->tm_min %d\n",tm->tm_hour,tm->tm_min);
    return 0;
}

outputs tm->tm_mday 15 tm->tm_hour 11 tm->tm_min 33

and tm->tm_mday 15 tm->tm_hour 6 tm->tm_min 3

Upvotes: 1

Views: 225

Answers (2)

Arun Taylor
Arun Taylor

Reputation: 1572

t1 in your code is time in seconds since 00:00:00 UTC, 1970-01-01. If you are getting different times on different machines, it means real time clocks on these machines are not synchronized, assuming they are configured to be in the same timezones.

Upvotes: 0

alk
alk

Reputation: 70941

Hardware clock and the time zone define the local time.

Upvotes: 2

Related Questions