OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) API epoch time question

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #45555

    BobSutn
    Participant

    I am writing a Java program to access the OSPI using the supplied API. Using JSON to query device time (devt) returns a long value of 1489421723. This translates to 13/03/2017 12:15 PM but this date/time value is four hours less than the actual local computer time. That is, the query was made at 13/03/2017 04:15 PM.

    devt​: Device time (epoch time). This is always the local time.

    My Java code to calculate the date/time:

    Long devt = 1489421723:
    Date date = new Date();
    date.setTime((long) devt * 1000);
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    String str = df.format(date);
    System.out.println(str + "  devt = " + devt);

    Does anybody know why this discrepancy exists?

    #45585

    Ray
    Keymaster

    The devt returned by the controller is always GMT+0. That combined with the time zone settings gives you the correct local time. The reason it’s done this way is so that the controller just needs to store GMT+0 time, and it remains the same whichever time zone you are in.

    #45593

    BobSutn
    Participant

    Ok, now I understand. I’ll have to adjust the returned value to account for my time zone. Thanx Ray.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) API epoch time question