on 05-23-2016 2:37 PM
Hi All,
Could anyone please let me know if there is a way to convert the system time(of any zone) to EST zone through code.
Thanks in advance.
Thanks,
Lavanya
Hi,
there are converting functions in wiondows api.
Here is a example code to convert UTC to local time:
// local 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
// local 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"
// 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
//PowerBuilder datetime -> SYSTEMTIME (für 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rene,
Thank you very much for the response.
Does this convert any time to EST time zone irrespective of what is set on the desktop currently.
Or in the other way round can we get EST time at any particular point of time instead of retrieving the system time and then converting it to EST.
Regards,
Lavanya
I have only used the conversion from UTC to local time.
More information about windows time functions:
There seems to be no function for convertion from one time zone to a second time zone so you may probably use two steps: TZ1 -> UTC -> TZ2 (TzSpecificLocalTimeToSystemTime and SystemTimeToTzSpecificLocalTime)
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.