Page 1 of 1

TimeZoneOffset()

Posted: Mon Aug 14, 2006 2:02 pm
by Rescator
Originally by netmaestro but I modified it a bit!
It returns the timezone offset in seconds as well
so you can use normal "math" to modify the result of Date() directly.

Code: Select all

Procedure TimeZoneOffset()
 Protected result,mode
 mode=GetTimeZoneInformation_(@TZ.TIME_ZONE_INFORMATION)
 If mode=1
  result-TZ\Bias
 ElseIf mode=2
  result-TZ\Bias-TZ\DaylightBias
 EndIf
 ProcedureReturn result*60
EndProcedure

Debug TimeZoneOffset()

Posted: Mon Aug 14, 2006 2:10 pm
by Rescator
THe above returns the timezone offset as seconds "from" UTC.
So europe is + and the US would be - etc.

Alternatively it could also be implemented as:

Code: Select all

Procedure TimeZoneOffset()
 Protected result,mode
 mode=GetTimeZoneInformation_(@TZ.TIME_ZONE_INFORMATION)
 If mode=1
  result=TZ\Bias
 ElseIf mode=2
  result=TZ\Bias+TZ\DaylightBias
 EndIf
 ProcedureReturn result*60
EndProcedure

Debug TimeZoneOffset()
Same as previous suggestion but instead it's returned as a timezone offset modification value.

So one could simply do:

Code: Select all

Debug Date()+TimeZoneOffset()
Which should be better performance wise than doing

Code: Select all

Debug Date()-TimeZoneOffset()
as in the first example.

Either solution is fine though, but we do need TimeZoneOffset() in some form or shape :)
Especially since various internet protocols and software uses UTC.

Posted: Mon Aug 14, 2006 3:17 pm
by Flype
also, you can look at this thread :

http://www.purebasic.fr/english/viewtop ... t=timezone