How does the Linux system distinguish between gmtime and localtime

  
                

gmtime and localtime are two different functions. Many people are confused when using them. The following small series teaches you how to distinguish between gmtime and localtime under Linux, so that you can use it correctly next time.

Difference:

#include 《time.h》

#include 《stdio.h》

int main(int argc, char **argv )

{

time_t tmpcal_ptr = {0};

struct tm *tmp_ptr = NULL;

tmpcal_ptr = time(NULL);

printf(“tmpcal_ptr=%d\ ”, tmpcal_ptr);

tmp_ptr = gmtime(&tmpcal_ptr);

printf(“after gmtime, the time is: \ %d:%d:%d”, tmp_ptr-"tm_hour, tmp_ptr-"tm_min, tmp_ptr-"tm_sec);

tmp_ptr = localtime(&tmpcal_ptr);

printf (&afterquo;after localtime, the time is:\ %d:%d:%d”, tmp_ptr-"tm_hour, tmp_ptr-"tm_min, tmp_ptr-"tm_sec);

return 0;

}

results are as follows:

means that the basic, gmtime transferred out of the standard time zone 0:00

localtime is considered in the time zone Inside, the time of the current time zone that was transferred out. However, note that in some systems with embedded devices, the time zone is not set, and the time for both of them is 0 time zone.

The above is a description of the difference between gmtime and localtime functions in Linux. As can be seen from the above code running results, the usage of gmtime and localtime is somewhat different.

Copyright © Windows knowledge All Rights Reserved