Sample code for 30+ languages & platforms
DataFlex

Query NTP Server for Current Date/Time

Demonstrates how to query an NTP server to get the current date/time.

Note: This feature was added in Chilkat v9.5.0.96.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoJson
    Handle hoDt
    Boolean iBLocalTime
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    // Specify the NTP server domain.
    // Information is passed in a JSON object to allow for any unanticipated future optional information that might need to be provided.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "ntp_server" "pool.ntp.org" To iSuccess

    // Query the NTP server for the current date/time.
    Get Create (RefClass(cComCkDateTime)) To hoDt
    If (Not(IsComObjectCreated(hoDt))) Begin
        Send CreateComObject of hoDt
    End
    Get ComEmit Of hoJson To sTemp1
    Get ComSetFromNtpServer Of hoDt sTemp1 To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoDt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Show the date/time in various formats..
    Move True To iBLocalTime
    Get ComGetAsTimestamp Of hoDt iBLocalTime To sTemp1
    Showln sTemp1
    Get ComGetAsRfc822 Of hoDt iBLocalTime To sTemp1
    Showln sTemp1
    Get ComGetAsUnixTime Of hoDt iBLocalTime To iTemp1
    Showln iTemp1

    // Sample output:

    // 2023-10-31T09:43:27-05:00
    // Tue, 31 Oct 2023 09:43:27 -0500
    // 1698745407


End_Procedure