On 04 Aug 2002 18:54:44 +0300, Erez Doron <[EMAIL PROTECTED]> wrote:
> 
> i am writing a small app in C and i need to get the timezone
> ( e.g. -2:00 for israel )
> how do i do that ?
> 
> the timezone variable from <time.h> returns 0 

Bellow is my function for getting the offset (It should work on any
system, even M$Windoze). It is better than checking TZ because it
will have the DST included automatically.

Ehud.


static int get_ofst ( void )               /* compute offset from GMT */
{
#define FDAY 86400                         /* full day in seconds 24*60*60 */
#define HDAY 43200                         /* half day in seconds */
struct tm ofst;
long  tloc ;                               /* seconds from 1/1/1970 0.0.0 GMT */
int sec_ofst ;

   time (& tloc) ;                         /* get current time */
   ofst = *gmtime (& tloc) ;               /* find GMT hour */
   sec_ofst = ( ofst.tm_hour * 60 +
                ofst.tm_min ) * 60 +
                ofst.tm_sec ;              /* GMT hour (in seconds) */
   ofst = *localtime (& tloc) ;            /* find local hour */
   sec_ofst = ( ( ofst.tm_hour * 60 +
                  ofst.tm_min ) * 60 +
                  ofst.tm_sec - sec_ofst
                + FDAY ) % FDAY ;          /* Local - GMT hours (in seconds, 0-FDAY) */
   if ( sec_ofst > HDAY )
       sec_ofst -= FDAY ;                  /* sec_ofst in range -11:59:59 +12:00:00 */
   sprintf ( p_date , "%02d/%02d/%02d" ,   /* save date */
             ofst.tm_mday ,
             ( ofst.tm_mon + 1 ) ,
             ( ofst.tm_year % 100 ) ) ;
   return ( sec_ofst ) ;
}



-- 
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 mailto:[EMAIL PROTECTED]          Better  Safe  Than  Sorry

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to