I am working on Xero accounts Apis In json response i am getting date like below
\"Date\": \"/Date(1455447600000+1300)/\",
also same date
I should like to contribute the modern solution
Pattern jsonDatePattern = Pattern.compile("/Date\\((\\d+)([+-]\\d{4})\\)/");
String dateFromJson = "/Date(1455447600000+1300)/";
Matcher m = jsonDatePattern.matcher(dateFromJson);
if (m.matches()) {
long epochMillis = Long.parseLong(m.group(1));
String offsetString = m.group(2);
OffsetDateTime dateTime = Instant.ofEpochMilli(epochMillis)
.atOffset(ZoneOffset.of(offsetString));
System.out.println(dateTime);
}
Output:
2016-02-15T00:00+13:00
This agrees with the date and time in your JSON date string and additionally informs you of the UTC offset.
I am using and warmly recommending java.time, the modern Java date and time API. And discouraging the classes Date, Calendar and TimeZone used in the question and in the other answer. They are long outdated, and the modern Java date and time API is so much nicer to work with.
Oracle tutorial: Date Time explaining how to use java.time.