Reputation: 341
I been stuck trying to parse the following date format below:
2016-04-27T00:00:00+10:00
I've tried many combinations and can't seem to get it to work.
I would have thought this would work as it make the most sense to me - yyyy-MM-dd'T'HH:mmZ
Any ideas? Thanks
Upvotes: 0
Views: 1150
Reputation: 5598
In case you use Jackson for JSON parsing, you can simply annotate date field with @JsonFormat Annotation. Here's an example:
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss'Z'", timezone="GMT")
public Date date;
Upvotes: 1
Reputation: 9648
You are unable to parse it as you are not using the correct format. It should be yyyy-MM-dd'T'HH:mm:ssZ
instead of yyyy-MM-dd'T'HH:mmZ
.
Here is the code snippet:
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String input = "2016-04-27T00:00:00+10:00";
Date date = sf.parse(input);
Output:
Tue Apr 26 14:00:00 GMT 2016
Upvotes: 1