timezone offsets calculations
- New
- How-to
- Philip Troise
- PowerBuilder
- Sunday, 26 January 2025 03:04 PM UTC
I have to satisfy this date timeoffset requirment and I am having trouble
I think I have accpeted that windows API functiuons can do thid, but I do not understand or know what api function to use in what order to get a time offset for a particular day and time of a region. I know its 4 hours in eastern standard time at this time of the year. but can api functions determine this without know when day light savings starts each year. I believe they can, but what in what order ?
Datetime format Requirement:
The date and time in ISO 8601 format including the timezone offset (yyyy-mm-ddThh:mm:ss.nnn+hh:mm).
Must be sent as the local date/time of the merchant. For example, a request processed at a merchant in the Pacific time zone at 9:18am on April 15th 2021 would be sent as 2021-04-15T09:18:23.283-07:00
I was inform there was nothjing in PB to do this directly., so I turned to windows api functions for timezone and DST processing.
I found code on here, but having trouble omplemeting it.
1) SYSTEMTIME (for UTC) - What is suppose to happen here?
2) DateTime of_utc2local (datetime adtm_utc) - There is no of_utc2local function
FOUND CODE ON HERE USING PB code using windows api functions.
Hi,
here is an example for converting UTC to local time using Windows API.
(For conversion to UTC see function TzSpecificLocalTimeToSystemTime)
// external functions
protected Function boolean GetTimeZoneInformationForYear &
(uint year, &
char tz, &
ref os_time_zone_information lpTimeZoneInformation) Library "kernel32"
protected Function boolean SystemTimeToTzSpecificLocalTime &
(os_time_zone_information lpTimeZone, &
os_systemtime lpUniversalTime, &
ref os_systemtime lpLocalTime ) Library "kernel32"
// structures
type os_systemtime from structure
unsignedinteger wyear
unsignedinteger wmonth
unsignedinteger wdayofweek
unsignedinteger wday
unsignedinteger whour
unsignedinteger wminute
unsignedinteger wsecond
unsignedinteger wmilliseconds
end type
type os_time_zone_information from structure
long bias
integer standardname[32]
os_systemtime standarddate
long standardbias
integer daylightname[32]
os_systemtime daylightdate
long daylightbias
end type
// function datetime of_utc2local (datetime adtm_utc)
datetime ldtm_local
os_time_zone_information lstr_tzi
os_systemtime lstr_utc
os_systemtime lstr_local
char lc_c
boolean lb_rc
SetNull (ldtm_local)
//local time zone
lb_rc = GetTimeZoneInformationForYear (Year(Date(adtm_utc)), lc_c, lstr_tzi)
IF NOT lb_rc THEN return ldtm_local
SYSTEMTIME (for UTC)
lstr_UTC.wYear = Year(Date(adtm_utc))
lstr_UTC.wMonth = Month(Date(adtm_utc))
lstr_UTC.wDay = Day(Date(adtm_utc))
lstr_UTC.wHour = Hour(Time(adtm_utc))
lstr_UTC.wMinute = Minute(Time(adtm_utc))
lstr_UTC.wSecond = Second(Time(adtm_utc))
lstr_UTC.wMilliseconds = 0
//Convert to local time zone
lb_rc = SystemTimeToTzSpecificLocalTime (lstr_tzi, lstr_UTC, lstr_local)
IF NOT lb_rc THEN return ldtm_local
//Convert SYSTEMTIME to PowerBuilder datetime
ldtm_local = DateTime (Date (lstr_local.wYear, lstr_local.wMonth, lstr_local.wDay), &
Time (lstr_local.wHour, lstr_local.wMinute, lstr_local.wSecond))
return ldtm_local
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.