Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion from UTC(GMT) to localtime

Status
Not open for further replies.

neel68

Programmer
Oct 7, 2002
1
US
I am trying to convert UTC(GMT) time to local time in VB6. Any help is highly appreciable.

Thanks.
-- Neel
 
You could read the local time zone from the registry and adjust accordingly. The key is:

HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation

and there's a string value, StandardName.

The possible time zones each have a key under:

W9x/ME
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones

NT/2000/XP
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones

These won't help you much with determining the possible values in StandardName. Each time zone key has a value, Std, which doesn't correspond to the current setting in StandardName. For example I'm in GMT. StandardName is "GMT Standard Time" but under the Greenwich Standard Time key in time zones the value Std is "Greenwich Standard Time"

Have fun!

Paul Bent
Northwind IT Systems
 
Neel,

You can use the GetTimeZoneInformation() api to get the appropriate local time zone adjustments to your UTC time. You could also use the localtime() function in the C runtime to provide this functionality for you.
 
The following API call may also be useful in conjunction with the info provided earlier in the thread: SystemTimeToTzSpecificLocalTime

Assuming that you are on NT or better, and want the time for the settings on your local machine the sequence would be something like:

GetTimeZoneInformation
GetSystemTime
SystemTimeToTzSpecificLocalTime

If you want to do it for another timezone then, as paulbent says, you need to read the registry to build the correct TIME_ZONE_INFORMATION type, and this would replace the GetTimeZoneInformation step in the above pseudo-code.

Note that on W9x/Me the SystemTimeToTzSpecificLocalTime API call is not supported, so you would have to write your own...

Then just a few more lines of code, and you get:

mclock2.png


:) :) :)
 
strongm
>Assuming that you are on NT or better

would that be linux then? [poke]

Hope you are feeling better!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Neel,

Where are you getting your UTC time from? Is it "seconds since Jan 1 1970" (aka 'unix' time)?
 
mattKnight

Bah!

Must be better. Just about to head out to the pub...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top