Convert local time to gmt time without using TimeZone Env variable

Convert local time to gmt time without using TimeZone Env variable

Post by francois reygagn » Sat, 07 Apr 2001 18:40:09



The ftcs unix mktime use the function tzset to initialize time
conversion information by setting an environment variable. That is not
thread-safe.

As I want to work in multi_threaded design with different time-zone, one

per each thread, I can't use the unix standard fonctions like mktime. I
need a thread-safe function that converts a local-time attached to its
timezone into a GMT time as follow:

    void localtime_to_gmt(const char * timezone,  const struct tm
localtime,  time_t * gmt_time);

Is there a  sofftware which uses instead of TZ env variable a local time

zone variable attached to the process to convert a local time to GMT ?

Thanks for your help ?

Fran?ois REYGAGNE. Software Architect.
opt[e]way S.A., 2881 route des Crtes, BP308
06906 Sophia Antipolis Cedex, FRANCE
tl: +33 (0)4 92 95 27 01    http://www.opteway.com

 
 
 

Convert local time to gmt time without using TimeZone Env variable

Post by Mark Garret » Tue, 10 Apr 2001 08:41:00




Quote:> The ftcs unix mktime use the function tzset to initialize time
> conversion information by setting an environment variable. That is not
> thread-safe.

> As I want to work in multi_threaded design with different time-zone, one

> per each thread, I can't use the unix standard fonctions like mktime. I
> need a thread-safe function that converts a local-time attached to its
> timezone into a GMT time as follow:

> void localtime_to_gmt(const char * timezone,  const struct tm
> localtime,  time_t * gmt_time);

> Is there a  sofftware which uses instead of TZ env variable a local time

> zone variable attached to the process to convert a local time to GMT ?

You have always got tm_gmoff to work any tm structure back to GMT and you
can call gmtime_r eg.

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

main()
{
        time_t lt;
        struct tm       gmt;

        lt = time((time_t *) NULL);
        gmtime_r(&lt, &gmt);

Quote:}

RTFM

    Cheers
        Mark ;)

 
 
 

1. Convert local time to gmt time without using TimeZone Env variable

The ftcs unix mktime use the function tzset to initialize time
conversion information by setting an environment variable. That is not
thread-safe.

As I want to work in multi_threaded design with different time-zone, one

per each thread, I can't use the unix standard fonctions like mktime. I
need a thread-safe function that converts a local-time attached to its
timezone into a GMT time as follow:

    void localtime_to_gmt(const char * timezone,  const struct tm
localtime,  time_t * gmt_time);

Is there a  sofftware which uses instead of TZ env variable a local time

zone variable attached to the process to convert a local time to GMT ?

Thanks for your help ?

Fran?ois REYGAGNE. Software Architect.
opt[e]way S.A., 2881 route des Crtes, BP308
06906 Sophia Antipolis Cedex, FRANCE
tl: +33 (0)4 92 95 27 01
http://www.opteway.com

2. Cron Job

3. convert UT time in local time / local time in UT time

4. Go sol 7 to 9 now? (standalone, no networking)

5. Converting a *future* time in another timezone to local time ...

6. nested routing

7. Converting GMT to local time

8. Second Annual Hackers, Crackers & Sniffers Conference

9. timed (time daemon) and GMT

10. GMT-time & Samba an a time-server

11. Top shows GMT time i.s.o MDT time!

12. GMT vs. Local Time -- Some help please!

13. GMT and local time manipulation in Solaris 2.x