MangoAutomation / BACnet4J

BACnet/IP stack written in Java. Forked from http://sourceforge.net/projects/bacnet4j/
GNU General Public License v3.0
187 stars 111 forks source link

How to convert local-date to a usual date #30

Closed reki-cool closed 5 years ago

reki-cool commented 5 years ago

when I take Gson searlize the 'localData', it's show as Date [year\u003d118, month\u003dOCTOBER, day\u003d21, dayOfWeek\u003dSUNDAY]. how can i convert it to the style yyyy-MM-dd

reki-cool commented 5 years ago

I take Gson to solve them, the local-time field looks ok, but the local-date field looks so stanger

"localTime": "18:21:17.0",
"localDate": "Date [year\u003d118, month\u003dOCTOBER, day\u003d21, dayOfWeek\u003dSUNDAY]"
terrypacker commented 5 years ago

You comment is fairly vague but if you are just trying to convert a com.serotonin.bacnet4j.type.primitive.Date to a formatted String you would probably want to first make sure that it is actually a specific date instead of a matching pattern, then you can convert it to a GregorianCalendar and use standard java tools to print out whatever format you need.

private String formatDate(com.serotonin.bacnet4j.type.primitive.Date date) {
  if(date.isSpecific(){
     GregorianCalendar gc = date.calculateGC();

  }else{
     throw new Exception("Impossible");
  }
}
reki-cool commented 5 years ago

thank you very much! @terrypacker