-2

I have a web application where user can post the message to a restful API, so that that information can be saved in the database.

My problem when the data is sent from the UI, the date sent is "effStartDate":"2016-08-13" , but when i see the date value in the java code it is showing Fri Aug 12 20:00:00 EDT 2016.

I am using AngularJS,Spring and iBatis as the ORM tool. Attached are the screen shots with data sent from UI and what i see in the backend code.

can anyone help me with this?

enter image description here

enter image description here

Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71
KB.
  • 29
  • 1
  • 7

3 Answers3

1

You can add annotations to realize in the entity. (Have to rely on JackJson`s jar) and Then add in required fields "@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")"

ToQuery
  • 33
  • 6
  • I tried that, Date sent from UI - "2016-08-13 00:00:00" and Date i see in backend is "Fri Aug 12 12:00:00 EDT 2016" – KB. Aug 11 '16 at 16:41
0

You can try this use date format from javascript code to send requests to a server by REST api.

For example:

effStartDate.toISOString();

The toISOString() method returns a string in simplified extended ISO format

Ramon
  • 1,169
  • 11
  • 25
  • When i try this , UI Date = "effStartDate":"2016-08-28T00:19:21.000Z" , Data seen at the backend Sat Aug 27 20:19:21 EDT 2016 – KB. Aug 11 '16 at 17:35
  • Date is a fine field type for this. You can make the JSON parse by using ObjectMapper.setDateFormat DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm a z"); myObjectMapper.setDateFormat(df); – Pankaj Mukati Aug 12 '16 at 07:39
0

You can treat the date as a string. Something like this @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")

user2254601
  • 164
  • 2
  • 8