View Full Version : Get the users timezone?
Gabis
01-30-2006, 05:48 PM
anyone know how I could do this?
My current project requires that an exported XML document be timestamped in Zulu time, IE -5:00 from EST, -8:00 from PST. So, depending on the users timezone the System.GetTime result would need to be modified.
I suppose it might be easier to use an http query to an atomic clock or something, maybe a PHP form that gives the current Zulu time.
But still, could this be done from AMS itself without outside resources?
TJ_Tigger
01-30-2006, 06:26 PM
There is a registry setting for time zone
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\TimeZoneInformation
And a key that contains the offset from UTC in minutes
Bias or ActiveTimeBias --Hex value of minutes
you can use tonumber(HEX, 10) to convert a hex number to a decimal number.
Dialog.Message("", tonumber(Registry.GetValue(HKEY_LOCAL_MACHINE, "\\SYSTEM\\CurrentControlSet\\Control\\TimeZoneInfo rmation", "ActiveTimeBias", true),10));
Bias
Specifies the current bias, in minutes, for local time translation on this computer.
The bias is the difference, in minutes, between UTC and local time.
All translations between UTC and local time are based on the following formula.
UTC = local time + bias
This member is required.
link (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecoreos5/html/wce50lrftimezoneinformation.asp)
Tigg
Gabis
01-30-2006, 07:19 PM
awesome. thats purrrrfect haha im lame. seriously, thanks a ton tigg. as always, you rock!
Corey
01-30-2006, 07:31 PM
Bippity boppity boo.
Gabis
01-30-2006, 08:16 PM
hmm.. ok.. im having trouble here.
it works fine for my timezone, and all the ones ive tried that are -'s.. but once i tried the +'s.. things got funkeh. the numbers being output are overly huge. like 4294967236 for +1:00.. now.. thats a helluva lot more than 60 minutes :D so im confused.. dunno how to do this. im sure im just missing something obvious, and im gonna keep hacking at it. but right now im stumped.
TJ_Tigger
01-30-2006, 09:08 PM
Try taking the number returned and subtract it from 4294967296 to get the number of minutes you add to the current time. You may want to add an if/then to check if it is over 720 then subtract. Like this
nTimeOffset = tonumber(Registry.GetValue(HKEY_LOCAL_MACHINE, "\\SYSTEM\\CurrentControlSet\\Control\\TimeZoneInfo rmation", "ActiveTimeBias", true),10);
if nTimeOffset > 720 then
nAdd = true;
nTimeOffset = 4294967296 - nTimeOffset;
else
nAdd = false;
end
if nAdd then
--Positive offset
else
--negative offset
end
HTH
Tigg
Gabis
01-31-2006, 02:45 PM
that did the trick. again, thanks a ton tigg.
question though, where did you get that number? or did you just add 60 to the one i provided? im thinking i mustve missed something in the msdn link, but i dont remember anything about that.
TJ_Tigger
01-31-2006, 07:06 PM
I guessed at it. I figured that the value they were using for positive timezones were represented by using four bytes of data. This is a range of 0x00000000 or a decimal value of 0 (zero) and a max value is then 0xffffffff which has a value of 4294967295. The total number of digits is then 4294967296, so I tried to subtract the decimal value from that to determine the offset and it worked. A little guess work can't explain it but it worked.
Gabis
01-31-2006, 08:52 PM
Well wow, great guess! Thanks to your help ive got it working perfectly for the any time zone, even the ones with minutes involved. Now just to finish it up by having it make sure the date is UTC as well, but that shouldnt be too hard. Just tooo many hours at work today :D Ill prolly break down and finish at home though, ah well.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.