gmtime和localtime是两种不同的函数,不少人在使用的时候容易将两者混淆,下面小编就教你Linux下如何辨别gmtime和localtime的使用,以便你下次能够正确使用。
区别:
#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\n”, tmpcal_ptr);
tmp_ptr = gmtime(&tmpcal_ptr);
printf(“after gmtime, the time is:\n%d:%d:%d”, tmp_ptr-》tm_hour, tmp_ptr-》tm_min, tmp_ptr-》tm_sec);
tmp_ptr = localtime(&tmpcal_ptr);
printf(“after localtime, the time is:\n%d:%d:%d”, tmp_ptr-》tm_hour, tmp_ptr-》tm_min, tmp_ptr-》tm_sec);
return 0;
}
运行结果如下:
任何业绩的质变都来自于量变的积累。