` Printed Icetips Article

Icetips Article



Par2: UTC and Time server
2010-04-14 -- Richard Rose
 
SYSTEMTIME      GROUP,TYPE              !System time struct
wYear            ushort
wMonth           ushort
wDayOfWeek       ushort
wDay             ushort
wHour            ushort
wMinute          ushort
wSecond          ushort
wMilliseconds    ushort
                END


TIME_ZONE_INFORMATION   GROUP
Bias                    LONG
StandardName             byte,dim(64) !will clear to 0's
StandardDate             LIKE(systemTIME)
StandardBias             LONG
DaylightName             byte,dim(64)
DaylightDate             LIKE(SYSTEMTIME)
DaylightBias             LONG
                        END


TZ_Info                 Long
StandardBias            Long
DaylightBias            Long
Bias                    Long



    TZ_Info=GetTimeZoneInformation(Address(TIME_ZONE_INFORMATION))
    !Clear(StandardBias) !Hours from GMT
    !Clear(DaylightBias)

                               !Minutes                              Secs 
Hundredths
    DaylightBias        = ((0 - TIME_ZONE_INFORMATION.DaylightBias)  * 60 * 
100)
    StandardBias        = ((0 - TIME_ZONE_INFORMATION.StandardBias)  * 60 * 
100)
    Bias                = ((0 - TIME_ZONE_INFORMATION.Bias)          * 60 * 
100)

    !Message(Format(Daylightbias,@t7))
    !Message(Format(Standardbias,@t7))
    !Message(Format(bias,@t7))

    If TZ_Info = 2 !daylight

        MachineDetails.Property   = 'Timezone Daylight Saving'
        MachineDetails.Value      = 'On'
        Add(MachineDetails)
     Elsif tz_Info = 1 !std

        MachineDetails.Property   = 'Timezone Daylight Saving'
        MachineDetails.Value      = 'Off'
        Add(MachineDetails)
     Else !No Daylight saving

        MachineDetails.Property   = 'Timezone Daylight Saving'
        MachineDetails.Value      = 'Daylight Saving Not Used In This 
Region'
        Add(MachineDetails)
    End



    MachineDetails.Property   = 'Timezone Standard Bias'
    !MachineDetails.Value      = '(GMT ' & Format(bias,@t1) &')'
    IF StandardBias > 0
        MachineDetails.Value      = '(GMT +' & Format(Standardbias+1,@t1) &' 
Hrs)'
    ElsIf StandardBias < 0
        MachineDetails.Value      = '(GMT -' & Format(Standardbias-1,@t1) &' 
Hrs)'
    Else
        MachineDetails.Value      = '(GMT/UTC)'
    END
    Add(MachineDetails)


    MachineDetails.Property   = 'Timezone Daylight Saving Bias'
    IF DaylightBias > 0   !Greater than GMT/UTC
        MachineDetails.Value      = '(GMT +' & Format(DaylightBias+1,@t1) &' 
Hrs)'
    ElsIf DaylightBias < 0  !Less than GMT/UTC
        MachineDetails.Value      = '(GMT -' & Format(DaylightBias-1,@t1) &' 
Hrs)'
    Else
        MachineDetails.Value      = '(GMT/UTC)'
    END
    Add(MachineDetails)


    MachineDetails.Property   = 'Timezone Bias'
    IF Bias > 0   !Greater than GMT/UTC
        MachineDetails.Value      = '(GMT +' & Format(Bias+1,@t1) &' Hrs)'
    ElsIf Bias < 0  !Less than GMT/UTC
        MachineDetails.Value      = '(GMT -' & Format(Bias-1,@t1) &' Hrs)'
    Else
        MachineDetails.Value      = '(GMT/UTC)'
    END
    Add(MachineDetails)




    MachineDetails.Property   = 'Timezone Region'
    MachineDetails.Value      = 
GetReg(REG_CURRENT_USER,'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time 
Zones','TimeZoneKeyName')
    Add(MachineDetails)

Larry Sand adds:

You can use these relationships too:

GetSystemTime(systemtime) !this is current date and time in UTC

SystemTimeToFileTime(SystemTime, FileTime)  !convert to filetime
FileTimeToLocalFileTime(FileTime, LocalFileTime) !Now get the local filetime
FileTimeToSystemTime(LocalFileTime, LocalSystemTime)

The filetimes are hard to work with, that's why it's converted back to a 
system time structure at the end.

The systemtime structure is easy to convert back to clarion date and times 
with Date(), Deformat(), and Format().

ClarionStdDate = Date(LocalSystemTime.wMonth, |
                                           LocalSystemTime.wDay, |
                                           LocalSystemTime.wYear)
ClarionStdTime = Deformat(Format(LocalSystemTime.wHour, @n02) & |
                                 Format(LocalSystemTime.wMinute, @n02) &|
                                 Format(LocalSystemTime.wSecond, @n02), @T5)



Printed November 23, 2024, 8:20 pm
This article has been viewed/printed 35244 times.