2

When I call Get service, In the output json, 'createdDate' is coming -1 less than the actual date in database (in input json).

for ex. In the input json, Below is the date that is supposed to be stored in the database through post request.

{    
    "createdDate" : "2018-07-10" 
}

Now, When I call Get request, I am getting below json in which date is -1 less than the date in database(input json).

{     
    "createdDate" : "2018-07-09"
}

Here is my 'createdDate' column in pojo:

@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd", timezone="UTC")
@Column(name="created_date")
private Date createdDate;
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Ajay
  • 55
  • 3
  • 9
  • 3
    refer https://stackoverflow.com/questions/31622254/lost-one-day-for-a-date – sasikumar Dec 27 '18 at 12:11
  • 1
    could it be a time zone issue? like your database server time zone vs application server time zone of your GET request is different ? – mkjh Dec 27 '18 at 12:13
  • I’m sorry, we can’t answer the question based on the information you have given. You would at least have specify the datatype in the database and show how you retrieve the date from there. – Ole V.V. Dec 27 '18 at 12:16
  • timezone=" UTC " did you change your local time to UTC time? – Himeshgiri gosvami Dec 27 '18 at 12:17
  • The `Date` class is poorly designed and long outdated. And despite its name it doesn’t represent a date (which is probably also part of the reason for your problem). Use `LocalDate` instead if there’s any way your JSON library can handle it. – Ole V.V. Dec 27 '18 at 12:19
  • @OleV.V. - Thanks, It worked :) – Ajay Dec 27 '18 at 16:02

1 Answers1

1

most obvious reason for this to happen is if your database is returning date in utc and you are confusing it with local date,converting the date from database into local date would work

rahul
  • 880
  • 3
  • 14
  • 25