I've got a REST API that returns JSON data with dates in a standard ISO-8601 format: yyyy-MM-ddTHH:mm:ss:
{
id: 4
version: 3
code: "ADSFASDF"
definition: "asdflkj"
type: "CONTAINER"
value: "1234"
active: "false"
formula: false
validTo: "2014-12-31T05:00:00"
validFrom: "2010-12-31T10:00:00"
}
My issue is that I'm not quite sure how to deal with this in AngularJS. I have a $resource
which GETs, POSTs, etc my API endpoints, but when my data is returned, it is stored in my JS object as as String. I figure that it would be easier to handle as a Date() or a Moment().
In Java, I can use a JsonDeserializer
to ensure that all JSON data is properly converted prior to being assigned to the model, but I don't know if there is a similar mechanism in AngularJS.
I've searched around, but can't seem to find anything that implements a generalized solution. I realize that I can use a transformResponse
function in my $resource
, but that seems like a lot of repeated configuration for every data type that may contain a date.
This leads me to wonder if returning the date in an ISO-8601 format is the best way to proceed? If AngularJS doesn't support it out of the box, I presume that there must be an easier way to deal with dates. How does one deal with dates in AngularJS? Should I just be treating them as text/string objects, and have the API return a pre-formatted version? If so, what is the most flexible format to use in an HTML5 date input box, etc?