Please be aware when handling timezones that some parts of the world have half hour timezone offsets, this is why the OS uses minutes instead of hours for timezone offsets.
http://www.timeanddate.com/time/time-zo ... sting.html
Something like
Code: Select all
Debug "Hour Time Offset = " + Str(TimeZoneOffset()/3600) + " Hours"
is wrong as it would cause a half hour timezone to get rounded a half hour wrong.
A quick fix would be
Code: Select all
Debug "Hour Time Offset = " + StrF(TimeZoneOffset()/3600.0,1) + " Hours"
(for display purposes only, and you may also need to use StrD() instead of StrF() due to 32bit not being that good with precision of integer numbers larger than 32767 if I recall correctly).
Also, if you want UTC but formatted then you could do the following:
Code: Select all
EnableExplicit
Procedure.s CustomFormatDateUTC()
Protected st.SYSTEMTIME,weekday$,month$,ampm$
GetSystemTime_(st)
Select st\wDayOfWeek
Case 0
weekday$="Sunday"
Case 1
weekday$="Monday"
Case 2
weekday$="Tuesday"
Case 3
weekday$="Wednesday"
Case 4
weekday$="Thursday"
Case 5
weekday$="Friday"
Case 6
weekday$="Saturday"
Endselect
Select st\wMonth
Case 1
month$="January"
Case 2
month$="Februrary"
Case 3
month$="Mars"
Case 4
month$="Aril"
Case 5
month$="May"
Case 6
month$="June"
Case 7
month$="July"
Case 8
month$="August"
Case 9
month$="September"
Case 10
month$="October"
Case 11
month$="November"
Case 12
month$="December"
Endselect
Select st\wHour
Case 0 To 11
ampm$="AM"
Default
ampm$="PM"
EndSelect
ProcedureReturn Str(st\wDay)+" "+month$+" "+Str(st\wYear)+", "+weekday$+" "+Str(st\wHour)+":"+RSet(Str(st\wMinute),2,"0")+" "+ampm$+"."
EndProcedure
Debug CustomFormatDateUTC()
No need to get the TimeZone as GetSystemTime_() gets you the UTC date and time (unaffected by timezones).
The code in the first post has one weakness in that the examples use FormatDate() and I'm just guessing here but I think FormatDate() is affected by timezone changes so if you want UTC then you should get the UTC date and time and avoid applying a timezone correction to get UTC.
If you need to use something like Date() or FormatDate() then you might need/want to do it twice to make sure no timezone change occurred while you where fetching/formatting the date.
I.e.
Get timezone
Get date
format date
get timezone
is timezone offset different than a moment ago? If so then re-format the date.
You might wonder what use GetSystemTime_() is, myself I'd use it for database entries or filenames etc as it's guaranteed to be unaffected by timezones and offsets.
I would probably in the case of a database or filename use it as a number, see code here:
http://www.purebasic.fr/english/viewtop ... 12&t=61132