6 Replies Latest reply on Aug 22, 2016 11:21 AM by magrawal RSS
    magrawal Apprentice

    how to convert a string into datetime using service in thingworx?

    Hi,

    I have a use case where I am receiving following JSON payload(example payload) into loadJSON property.

    {"time":"2016-08-02 19:00:00","temperature":Temp}

     

    I have created following two logged properties in my Thing(DemoThing) followed by generic ThingTemplate :
    1)Timestamp(BaseType DateTime)

    2)and Temp(BaseType Number)

     

    Now, to retrieve values for above mentioned properties from JSON payload I wrote following script in my service

    Things["DemoThing"].Temp=Things["DemoThing"].loadJSON.temperature

    Things["DemoThing"].Timestamp=Things["DemoThing"].loadJSON.time

     

    when I tried to execute service I received following error:
    Unable To Convert From java.lang.String to DATETIME Cause: Unable To Convert From java.lang.String to DATETIME]


    So I modified Service as following:

    Things["DemoThing"].Temp=Things["DemoThing"].loadJSON.temperature

    var timeString= Things["DemoThing"].loadJSON.time

    Things["DemoThing"].Timestamp=new Date(timeString)

    Now Service executed without any error but values of properties set as:
    1)Timestamp: 1970-01-01 0:00:00 (not correct, I was expecting 2016-08-02 19:00:00)

    2) Temp: Temp (expected)

     

    now I am not getting how to convert a string into datetime using service in thingworx?

    so I am looking for a help as soon as possible.

     

     

    Thanks in advance

     

    Meenakshi