Datepicker with Json datetime

1,295 views
Skip to first unread message

E_lexy

unread,
May 28, 2012, 9:21:21 AM5/28/12
to ang...@googlegroups.com
I have a datepicker that does not play nice with my backend.

My backend (http://jmsyst.com/bundles/JMSSerializerBundle) serializes php DateTime objects like this:
"1923-10-07T22:00:00+0000"
This gets interpreted by Angular just fine.

When I implement the datepicker the date is not seen in the picker and what is sent back changes to this format:
"1931-09-07T22:00:00.000Z"

Which my server doesn't understand.

What is the right way to do this?

Peter Bacon Darwin

unread,
May 28, 2012, 9:38:44 AM5/28/12
to ang...@googlegroups.com
Could you elaborate, perhaps with a sample of the code you are using?
What do you mean by Angular interprets the first date string?  What exactly is interpreting it?
What do you mean by the date is not seen in the picker?  Are you setting the ng-model value to something you received from the server?  Is the value a string or a Date object?
What do you mean by "sent back" sent back from where?
Pete

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/7eo3TB4SiIEJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

E_lexy

unread,
May 28, 2012, 10:03:08 AM5/28/12
to ang...@googlegroups.com
Sorry, i thought I had pasted my fiddle:
Pete

To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

Peter Bacon Darwin

unread,
May 28, 2012, 10:07:49 AM5/28/12
to ang...@googlegroups.com

This fiddle works for me. What doesn't work for you?

...from my mobile.

To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/zYOcZ1r6v94J.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.

Pawel Kozlowski

unread,
May 28, 2012, 10:28:07 AM5/28/12
to ang...@googlegroups.com
Hi!

On Mon, May 28, 2012 at 3:21 PM, E_lexy <alex...@gmail.com> wrote:

> When I implement the datepicker the date is not seen in the picker and what
> is sent back changes to this format:
> "1931-09-07T22:00:00.000Z"

Maybe I'm missing sth here but I believe that your issue has nothing
to do with angular.js but it is simply a matter of JavaScript date
objects serialization to a format that your backend can interpret
correctly (whatever 'correctly' means here but I assume that it means
converting strings to Date objects on your backend side).

Just changed your fiddle a but to illustrate that the date picker
correctly binds a JS Date object back to the model:
http://jsfiddle.net/pkozlowski_opensource/ddJb7/1/

> Which my server doesn't understand.
> What is the right way to do this?

Provided that in angular we've got valid JavaScript Date objects
you've got basically 2 options:
1) Convert JS dates to the string form that your backend can understand.
2) Make your backend understand the current serialization format.

It is a bit hard to say more without knowing how data are sent from a
browser and de-serialized on the backend side but I hope that my input
will point you in the right direction.

Cheers,
Pawel

Piotr T

unread,
Apr 24, 2014, 12:06:14 PM4/24/14
to ang...@googlegroups.com
Your datetime is converted to ISO8601 format. "1931-09-07T22:00:00.000Z" is a datetime in UTC time zone. In .net to deserialize it correctly use datetimeoffset

ISO8601 http://en.wikipedia.org/wiki/ISO_8601
Reply all
Reply to author
Forward
0 new messages