0

I'm parsing a JSON file with elements like this:

{
  "text": "Burn off. Goulburn Mulwaree (974 Currawang Road, Gundary) at 5 Mar 2017 12:44 #NSWRFS #Burnoff #NSWFires",
  "user": {
    "id": "4721717942",
    "name": "NSW Fire Updates"
  },
  "lang": "en",
  "coordinates": {
    "coordinates": [
      149.67931151,
      -34.83702803
    ],
    "type": "Point"
  },
  "created_at": "Sun Mar 05 03:39:31 +0000 2017"
}

I have successfully parsed all the objects within this file.

But for the object created_at, I want to make it into a ZonedTimeDate type. SO that I can do operations on them. Currently I'm just using String. Here is my current implementation:

public class Tweet {
    private String created_at;

    public Tweet() {
    }

    public String getCreated_at() {
        return created_at;
    }

    public void setCreated_at(String created_at) {
        this.created_at = created_at;
    }

    // Rest of class ...
}
Kutam
  • 87
  • 2
  • 12
  • Which JSON parser are you using? Also, `ZonedDateTime` requires knowing the time zone, but you don't have a time zone in that string, only an offset. Perhaps you should use `OffsetDateTime` instead. – RealSkeptic Apr 12 '17 at 17:46
  • im using Jackson. cant i just produce the Date and Time then? – Kutam Apr 12 '17 at 17:47
  • What do you mean "Produce the date and time"? You can parse that string into an `OffsetDateTime`, not into a `ZonedDateTime`. – RealSkeptic Apr 12 '17 at 17:49
  • I mean, so produce the Date and Time without having the Zone available. How would i use offsetdatetime? – Kutam Apr 12 '17 at 17:52
  • @RealSkeptic `ZonedDateTime` can handle pure offsets too. E.g. `ZonedDateTime.parse("Sun Mar 05 03:39:31 +0000 2017", DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss Z uuuu"))` returns `2017-03-05T03:39:31Z`. – Andreas Apr 12 '17 at 18:10

0 Answers0