#include <stdlib.h>#include <time.h>Include dependency graph for gmt2local.c:

Go to the source code of this file.
Functions | |
| int32_t | gmt2local (time_t t) |
| Returns the difference between gmt and local time in seconds. This function is borrowed from tcpdump (www.tcpdump.org/). | |
|
|
Returns the difference between gmt and local time in seconds. This function is borrowed from tcpdump (www.tcpdump.org/).
Definition at line 29 of file gmt2local.c. Referenced by main(). 00030 { 00031 register int dt, dir; 00032 register struct tm *gmt, *loc; 00033 struct tm sgmt; 00034 00035 if (t == 0) 00036 t = time(NULL); 00037 gmt = &sgmt; 00038 *gmt = *gmtime(&t); 00039 loc = localtime(&t); 00040 dt = (loc->tm_hour - gmt->tm_hour) * 60 * 60 + 00041 (loc->tm_min - gmt->tm_min) * 60; 00042 00043 /* 00044 * If the year or julian day is different, we span 00:00 GMT 00045 * and must add or subtract a day. Check the year first to 00046 * avoid problems when the julian day wraps. 00047 */ 00048 dir = loc->tm_year - gmt->tm_year; 00049 if (dir == 0) 00050 dir = loc->tm_yday - gmt->tm_yday; 00051 dt += dir * 24 * 60 * 60; 00052 00053 return (dt); 00054 }
|
1.4.3-20050530