JQuery datepicker + Rails 3.2.8 + AngularJS: show and save release date

It's hard for me to work triad + angularjs + jQuery rails.

The first problem is showing the date retrieved from the backend. When the user interface requests data from the backend, at some point it receives the following in JSON notation.

{"id":1,"ragione_sociale":"FrigoCaserta srl","indirizzo":"Strada provinciale Gricignano d'Aversa","cap":"81030","citta":"Gricignano d'Aversa","provincia":"CE","partita_iva":"1234","codice_fiscale":null,"tipo_contratto":"Orario","costo":"0.0","inizio":"2012-05-01","fine":"2013-09-22","$$hashKey":"005"}

The corresponding fields are "inizio" and "fine" (respectively, the start and end dates).

The Rails time zone is set to Europe / Rome.

Datepicker options are set to: {dateFormat: 'dd / mm / yy'}

Thus, I expected the input field to display the date "inizio" as: 01/05/2012 but instead I am returning: 03/24/2018.

Changing the dateFormat parameter to "yy-mm-dd" shows the correct date, but with an undesirable separator and format (2012-05-01) ...

However, what happens behind the scenes is that the displayed object is somewhat manipulated and becomes something like this:

{"id":1,"ragione_sociale":"FrigoCaserta srl","indirizzo":"Strada provinciale Gricignano d'Aversa","cap":"81030","citta":"Gricignano d'Aversa","provincia":"CE","partita_iva":"1234","codice_fiscale":null,"tipo_contratto":"Orario","costo":"0.0","inizio":"2012-04-30T22:00:00.000Z", ...

Please note that the "inizio" field now translates from "2012-05-01" to "2012-04-30T22: 00: 00.000Z"

Now, when I submit the form to the backend, everything goes up, since the rails are the new value for "inizio" in datepicker format. The database field, which is just a date, makes the time information disappear, and the rest only the (wrong) date stored in the model.

I know that datepicker has localization options, but I can’t find anything related to the time zone that I could change to fix this unwanted behavior.

, backend , , .

?

StackOverflow .

.

+5

All Articles