Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Time Zones
Message
From
22/09/2008 10:58:46
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
 
 
To
22/09/2008 09:03:22
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01349318
Message ID:
01349488
Views:
22
>>Hi Jay.
>>
>>>I'm communicating with a server that is in Iowa. When I get a response back from them, it is in CST, but I need it for whatever time zone the application is running in. How can I know this, and convert it? There is no guarantee that the server will always be in Iowa either. For now that isn't the burning issue, but if there is a way to handle that, I would be interested in how.
>>
>>http://doughennig.blogspot.com/2008/09/getting-time-zone-information.html should help.
>>
>>Doug
>
>I ran it with this at the end:
>
>? DATETIME() - lnTimeZoneOffset
>
>And it said that there was a 4 hour difference, but I'm running it on my laptop. Shouldn't it have just returned the current date and time?

Yes, I know I'm posting to myself. Doug must be busy, but I really need to figure this out. Can anyone see in the code why it would offset by 4 hours rather than just return the current date and time since it's all in the same time zone?
* Doug Hennig's code.

* Here's some code that retrieves local time zone information:

LOCAL ;
	lcTimeZone, ;
	lnID, ;
	lnStandardOffset, ;
	lnDaylightOffset

* Declare the time zone information API function and get the time zone
* information.

#DEFINE TIME_ZONE_SIZE  172
DECLARE INTEGER GetTimeZoneInformation IN kernel32 ;
	STRING @lpTimeZoneInformation
lcTimeZone = REPLICATE(CHR(0), TIME_ZONE_SIZE)
lnID       = GetTimeZoneInformation(@lcTimeZone)

* Determine the standard and daylight time offset.

lnStandardOffset = CTOBIN(SUBSTR(lcTimeZone,   1, 4), '4RS')
lnDaylightOffset = CTOBIN(SUBSTR(lcTimeZone, 169, 4), '4RS')

* Determine the total offset based on whether the computer is on daylight
* time or not. Get the description for the time zone.

IF lnID = 2  && daylight time
	lcTimeZoneDesc   = STRTRAN(STRCONV(SUBSTR(lcTimeZone, 89, 64), ;
		6), CHR(0), '')
	lnTimeZoneOffset = (lnStandardOffset + lnDaylightOffset) * 60
ELSE   && standard time
	lcTimeZoneDesc   = STRTRAN(STRCONV(SUBSTR(lcTimeZone,  5, 64), ;
		6), CHR(0), '')
	lnTimeZoneOffset = lnStandardOffset * 60
ENDIF lnID = 2


* You can then add lnTimeZoneOffset to a local time value to get a time in Greenwich
* Mean Time (GMT) or subtract lnTimeZoneOffset from a time value in GMT to obtain a
* local time value.

? DATETIME() - lnTimeZoneOffset
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform