Discussion:
Converting from GMT
(too old to reply)
Ken
2005-11-08 18:03:43 UTC
Permalink
I must be missing something as this would seem obvious, but what is the API
call to get the current GMT offset?

I have a date that is GMT. I use a COleDateTime object to format the
date/time for the user in their preferred format. However, COleDateTime is
ignorant of DST or GMT. However, CTime apparently deals with GMT but has
lower resolution and is not as nice to work with for formatting.

I think my preferred method would be to add/subtract the GMT offset to the
COleDateTime object, but I'm not quite sure what API to call to get the
offset.
AliR
2005-11-08 19:18:05 UTC
Permalink
You can call GetTimeZoneInformation(...) to get the difference between local
time and UTC (GMT)

or you can use CTime so you can get the difference

CTime time(CTime::GetCurrentTime());
tm t1 = *(time.GetLocalTm());
tm t2 = *(time.GetGmtTm());

TRACE("Difference between local time and GMT is %d hours.\n",
t1.tm_hour - t2.tm_hour);

AliR.
Post by Ken
I must be missing something as this would seem obvious, but what is the API
call to get the current GMT offset?
I have a date that is GMT. I use a COleDateTime object to format the
date/time for the user in their preferred format. However, COleDateTime is
ignorant of DST or GMT. However, CTime apparently deals with GMT but has
lower resolution and is not as nice to work with for formatting.
I think my preferred method would be to add/subtract the GMT offset to the
COleDateTime object, but I'm not quite sure what API to call to get the
offset.
leov SpamMeNot
2005-11-17 20:13:48 UTC
Permalink
If you KNOW that the time you have is UTC, you can convert it to Local time
by using the following APIs:
SystemTimeToFileTime // Convert UTC time to a FileTime format
FileTimeToLocalFileTime // Convert that FileTime to a local time using
GetTimeZoneInformation
FileTimeToSystemTime // Convert the resulting time back to SystemTime,
which you can then use to construct whatever date/time class you want.

Now, from this information, I'll give you a treat if you can tell me how to
convert from LocalTime to UTC. <g>
Post by Ken
I must be missing something as this would seem obvious, but what is the API
call to get the current GMT offset?
I have a date that is GMT. I use a COleDateTime object to format the
date/time for the user in their preferred format. However, COleDateTime is
ignorant of DST or GMT. However, CTime apparently deals with GMT but has
lower resolution and is not as nice to work with for formatting.
I think my preferred method would be to add/subtract the GMT offset to the
COleDateTime object, but I'm not quite sure what API to call to get the
offset.
Continue reading on narkive:
Loading...