class, TimeZone, MBS Util Plugin (Main), class TimeZoneMBS,
Mac: Yes, Win: Yes, Linux: No, Console & Web: Yes, Feedback.
Function: Allows you to access information about the current time zone.
Example:
dim t as new TimeZoneMBS
MsgBox str(t.GmtDeltaTotalseconds)
property GmtDeltaHours as integer
property GmtDeltaMinutes as integer
property GmtDeltaSeconds as integer
property GmtDeltaTotalseconds as integer
property Latitude as double
property Longitude as double
Hi both,
Thanks for this.
I need the actual timezone name - like Europe/London or Australia/Perth - not just the offset from GMT. The example I posted at the top gives the name, but TimeZoneMBS just gives me the offset.
H
I added the two new properties for my plugin class.
But well, they are localized and for me “Mitteleuropische Zeit”.
SO maybe not what Hamish looks for?
to find out which is active I had to correct the fact that I was ignoring a return value from GetTimeZoneInformation
and use that to highlight the current one, like…
soft declare function GetTimeZoneInformation lib "Kernel32.dll" ( lpTimeZoneInformation as ptr ) as int32
dim active_timezone as integer
dim mbTimeZoneInformation as memoryblock
mbTimeZoneInformation = new memoryblock(172)
active_timezone = GetTimeZoneInformation( mbTimeZoneInformation )
self.txtStdName.Bold = false
self.txtStdName.text = mbTimeZoneInformation.WString(4)
self.txtDaylightName.Bold = false
self.txtDaylightName.text = mbTimeZoneInformation.WString(88)
if active_timezone = 1 then self.txtStdName.Bold = true
if active_timezone = 2 then self.txtDaylightName.Bold = true
The information is stored in the Registry. Here is how to get it, using a slightly modified version of the Registry documentation page :
[code] // get a registry key
Dim reg As New RegistryItem(“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Romance Standard Time”)
Dim TimeZ As String
// now we look on all values on this key
For i As Integer = 0 To reg.KeyCount- 1
Dim name As String = reg.Name(i)
Dim value As Variant = reg.Value(i)
if name = “Display” then
TimeZ = reg.Value(i)
exit
end if
Next
// and display the time zone as cities
MsgBox TimeZ
[/code]
This works for standard configurations. I noticed there are numbers of other keys in \Time Zones\ like “Ulaanbaatar Standard Time” , “US Eastern Standard Time” and “US Mountain Time” which could be used instead by custom configurations. But playing on my Windows 8.1 64 bit with the Date/time Control Panel, the value set for the city goes always in “Romance Standard Time”.
You can also use windows wmi class win32_timezone with OLEObject:
// This example will get the computer system running Windows timezone
//http://library.wmifun.net/cimv2/win32_timezone.html
//http://msdn.microsoft.com/en-us/library/aa394498%28v=vs.85%29.aspx
Dim locator, objWMIService, objs, objProperty As OLEOBJECT
Dim nobjs as Integer
// Connect to WMI
locator = new oleObject("WbemScripting.SWbemlocator", true)
Dim wmiServiceParams(2) as variant
wmiServiceParams(1) = "."
wmiServiceParams(2) = "root\\cimv2"
objWMIService= locator.invoke("ConnectServer", wmiServiceParams)
// Run the WMI query
objs = objWMIService.ExecQuery ("SELECT * FROM Win32_TimeZone")
nobjs = objs.count - 1
For i as integer = 0 to nobjs
Dim stringData As String
objProperty = objs.ItemIndex(nobjs)
// ItemIndex() is not supported in Windows XP only from Windows Vista and upwards
stringData = "DaylightName: " + objProperty.Value("DaylightName") + EndOfLine
stringData = stringData + "TimeZone: " + objProperty.Value("StandardName") + EndOfLine
msgbox stringData
Next
locator = Nil
exception err as oleexception
msgbox err.message
Neither of these quite work; John’s gives me GMT Standard Time and GMT Daylight Time; Michel’s gives me (UTC+01:00) Brussels, Copenhagen, Madrid, Paris.
Neither of these quite work; John’s gives me GMT Standard Time and GMT Daylight Time; Michel’s gives me (UTC+01:00) Brussels, Copenhagen, Madrid, Paris.
[quote=82657:@Hamish Symington]Neither of these quite work; John’s gives me GMT Standard Time and GMT Daylight Time; Michel’s gives me (UTC+01:00) Brussels, Copenhagen, Madrid, Paris.
I’m after a value from the list at https://php.net/manual/en/timezones.php , which I don’t think is just a php list… So, a value like ‘Europe/London’.[/quote]
What you are after is not available in Windows settings anywhere. It is only part of PHP. I gave you a method for the closest Windows equivalent.
From one of these area/city values, you could get to GMT. For instance, “Europe/Paris” leads to GMT+1:00. But the reverse is not a simple reference. From GMT+1:00 you can get Europe/Brussels, Europe/Copenhagen, Europe/Madrid or Europe/Paris. Or even Europe/Berlin and Europe/Luxembourg. How are you going to manage that ?
Frankly, I do not think there is any simple way to obtain that. The information area/city is simply not stored in a windows computer. You are probably on a wild goose chase.
You should have told us about that list from the start go, it would have saved a lot of time…
Garbage in, garbage out. When the question is formulated without providing all terms of the equation, the answer is necessarily inadequate. The OP should have mentioned the PHP Manual list in the first place. That said, there is always something to learn. Like never providing solutions to a badly formulated query.
I want to get the user’s current timezone (e.g. Europe/London). I can do that on a Mac, simply, using an MBS call:
dim t as NSTimeZoneMBS = NSTimeZoneMBS.defaultTimeZone
MsgBox t.name
but I can’t find any way of doing so on Windows. Is there one?
Thanks,
Hamish[/quote]
Sounds like you need the tz database (at best)
See http://en.wikipedia.org/wiki/Tz_database#Move_to_ICANN
IANA maintains this now
Apparently, Mac OS X stores the time zone as a city. Which makes it easy to then pull for instance “America/New York” from the tz Database with a simple search.
Windows stores the time zone information as GMT and offset, plus cities information as stored in the Registry.
Unless one was to create a specific program for Windows that specifically uses city references or the Tz Database item and stores that, I do not see how it could be retrieved from a Windows system.
// Run the WMI query
objs = objWMIService.ExecQuery (“SELECT * FROM Win32_TimeZone”)
nobjs = objs.count - 1
For i as integer = 0 to nobjs
Dim stringData As String
objProperty = objs.ItemIndex(nobjs)
// ItemIndex() is not supported in Windows XP only from Windows Vista and upwards
stringData = "DaylightName: " + objProperty.Value("DaylightName") + EndOfLine
stringData = stringData + "TimeZone: " + objProperty.Value("StandardName") + EndOfLine
msgbox stringData
Next
locator = Nil
exception err as oleexception
msgbox err.message
[/code][/quote]
Oops… I had a typo in above code.
Line: objProperty = objs.ItemIndex(nobjs) should be corrected to: objProperty = objs.ItemIndex(i)
In this case it makes no difference as there are only one collection.