5 Replies Latest reply on Oct 19, 2015 9:56 AM by miikkae RSS
    miikkae Explorer

    How to fix DateTime property timezone in mashup?

    I've a console application sending data to ThingWorx service using .NET SDK, that adds those calls as an infotable property row.

     

    From the .NET app I debug the logs from the parameters send to the service and the dateTime seems ok but on ThingWorx mashup where I list the rows from that property in a grid, there's three hours offset.

     

    I've checked that the timezone is correct on the server running ThingWorx and tried using DateTime.SpecifyKind function in .NET to specify the time as DateTimeKind.Utc / DateTimeKind.Local before invoking the service with those parameters but nothing seems to be working.

     

    Could someone tell me how to get rid of this +3h offset? I'm trying to track live events from a sensor on mashup but it's kinda annoying to always get the time three hours in the future.

      • Re: How to fix DateTime property timezone in mashup?
        paic Collaborator

        The Thingworx server uses UTC, and then browser side that information is translated into the Time zone of the browser.

        Since you already made sure that UTC is correct on the server, then most likely the SDK is submitting time that is not UTC or the device is not set correctly?

          • Re: How to fix DateTime property timezone in mashup?
            miikkae Explorer

            The device talking to TWX SDK is outputting correct local time and in the program I escpecially set

            DateTime.SpecifyKind(date, DateTimeKind.Utc);

            The timezones are checked and correct in

            1. Current browser
            2. Device communicating to ThingWorx SDK
            3. ThingWorx server

             

            They are even all in the same timezone. Got no idea where the -3 hours come from.

              • Re: How to fix DateTime property timezone in mashup?
                paic Collaborator

                Is the property bound? or do you do any handling with the date/time before storing it?

                I would log the value at each step to the script log just to see if at anytime it changes at all.

                Beyond that I am not sure what might be going on with your setup.

                  • Re: How to fix DateTime property timezone in mashup?
                    miikkae Explorer

                    The property is not bound and actually the property is infotable "Just Infotable" that has the fields with datetime values.

                    Logging seems like be a great idea but I'm just afraid the time has changed when the input parameter arrives.

                    Thanks for the tip anyway, I'll try it tomorrow

                    • Re: How to fix DateTime property timezone in mashup?
                      miikkae Explorer

                      Finally had time and remembered to test this.

                      Logged the time parameter and while the log timestamp is 2015-10-19 16:05:11, it printed: Mon Oct 19 2015 19:05:13 GMT+0300 (EEST).

                      I'm guessing the two seconds are from clocks not in sync while the printed value should be the time launched from software and log timestamp the time the service was run (so it should be earlier or the same at latest).

                       

                      I finally fixed this by setting: time.setHours(time.getUTCHours()); before adding the row.

                      Doesn't seem like a great solution but the TWX service assumes the datetime is always current timezone (GMT+3) no matter what I timezone I set in .NET program.