taha manar
taha manar

Reputation: 577

SimpleDateFormat produce wrong result

I'm using a method to map an object to the a model which contains a date. In the eclipse debug I see the correct date but when displayed in postman I get the date minus one.

expected result : 2020-02-28

result : 2020-02-27T23:00:00.000+0000

this is my code:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
try {
    seance.setDate(dateFormat.parse("2020-02-28 11:04:05.768"));
    } catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Upvotes: 0

Views: 59

Answers (1)

Tainha
Tainha

Reputation: 106

I think your problem is timezone.

Default data serialize convert date in UTC, you can see '+0000'

The Date format result is ISO1861 (https://en.wikipedia.org/wiki/ISO_8601)

You can resolve your problem using custom data serialize or try set you env to expected date TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

Upvotes: 3

Related Questions