Q: How to convert GMT to local time? 
Author Message
 Q: How to convert GMT to local time?

Hi,

Consider the following:

I have a string, representing a date/time in the GMT
timezone. Now I want to convert it to the local timezone,
in my case CET.

The strings has the following syntax: 199710070630,
in the order yyyymmddhhmm.
Now I'm looking for a way to convert it to CET: 199710070830.

Anyone knows how to do this?


I'm not in the opportunity to read the newsgroups every day.

Thanks!

Dewi Jonker



Sat, 25 Mar 2000 03:00:00 GMT  
 Q: How to convert GMT to local time?

  Dewi> Hi, Consider the following:

  Dewi> I have a string, representing a date/time in the GMT
  Dewi> timezone. Now I want to convert it to the local timezone, in
  Dewi> my case CET.

  Dewi> The strings has the following syntax: 199710070630, in the
  Dewi> order yyyymmddhhmm.  Now I'm looking for a way to convert it
  Dewi> to CET: 199710070830.

  Dewi> Anyone knows how to do this?

Use the contents of your string and manually initialise a struct tm
and then use mktime on it.  Then use localtime() on the result.



Sat, 25 Mar 2000 03:00:00 GMT  
 Q: How to convert GMT to local time?

Quote:

> I have a string, representing a date/time in the GMT
> timezone. Now I want to convert it to the local timezone,
> in my case CET.
> The strings has the following syntax: 199710070630,
> in the order yyyymmddhhmm.
> Now I'm looking for a way to convert it to CET: 199710070830.
> Anyone knows how to do this?

I assume you want it done portably, so it will work in any time zone.

Look at the functions in time.h

localtime() and gmtime()

I have not tried this, it is just off the top of my head, but if you
generate the difference between the results of gmtime() and localtime()
(use the tm_hour member), for the same input time, you ought to be able
to save that value as a conversion factor.

#include <time.h>
/* You will probably want to wrap it into a function. */
struct tm *ltime, *utime;
int zonediff;

ltime = localtime( time() );
utime = gmtime( time() );
zonediff = utime.tm_hour - ltime.tm_hour;

Other factors will generally be the same (seconds, minutes, etc) unless
you 'cross' the International Date Line.  As long as the two calls do
not cross an hour boundry, you can check this by making another set of
calls to localtime() and gmtime() and making the appropriate comparison,
one set will almost have to be in the same hour, unless you run it on a
*really* slow computer.

--

Education is a companion which no misfortune can depress,
no crime can destroy, and no enemy can alienate...
at home a friend, abroad an introduction,
in solitude a solace, and in society and ornament.
                                Joseph Addison.
************************************************

You can't use void main() I have a patent on it!

************************************************

*    Remove the _JUNK_ when replying to me.    *
************************************************



Sun, 26 Mar 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to convert local time to gmt using a local variable time zone per process/thread

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

3. How to convert GMT time to local time?

4. Converting GMT to local time

5. GMT time and Local time ?

6. How to convert local time with specific time zone to UTC time in Win32 API

7. GMT to local time conv

8. Converting UTC time to local time

9. converting from Local Time to UTC time...

10. howDoI convert a time from GMT to PST

11. Converting VARIANT DATE to GreenwichMean Time (GMT) or LocalTime

12. How to convert local time to milliseconds?

 

 
Powered by phpBB® Forum Software