AngularJS date as iso8601

727 views
Skip to first unread message

Tarcisio A.

unread,
Jul 24, 2014, 4:37:43 PM7/24/14
to ang...@googlegroups.com
hi, im using Java Back-End, the MVC framework is called VRaptor4 and the date pattern is in Iso8601, so when the AngularJS send the data value to the server, i get the Caused by: java.text.ParseException: Unparseable date: "16/07/2014"


how can i change the date input to use the iso8601 format, if im not wrong, the pattern for Iso8601 is this one -> YYYY-MM-DDThh:mm:ss.sTZD


i tried new Date("16/07/2014"), Date,parse("16/07/2014")

and others, but all failed

Sander Elias

unread,
Jul 25, 2014, 2:41:43 AM7/25/14
to ang...@googlegroups.com

Hi Tarcisio,

Not really an angular issue, just plain old JS.;) Angular is server agnostic, so it does not know anything about your backend, and how it want’s to receive its dates.
new Date().toISOString() should do the trick.

Regards
Sander

ganaraj P R

unread,
Jul 25, 2014, 3:54:45 AM7/25/14
to ang...@googlegroups.com
Make note that toISOString is not supported in all browser ( especially the older IE's ).


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
Ganaraj P R

Juri

unread,
Jul 25, 2014, 3:58:08 AM7/25/14
to ang...@googlegroups.com
You might want to take a look at http://momentjs.com/ for Date handling. Turned out to be really useful in a couple of projects so far.

--
Juri Strumpflohner


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/BfTNwVHB7HI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

Tarcisio A.

unread,
Jul 25, 2014, 10:08:16 PM7/25/14
to ang...@googlegroups.com
thanks guys, but still a problem i think, or its normal to deal the date before it get displayed/sent?

for example, this date should get filled from the Database ISODate


<input type="date" ng-model="person.created" class="form-control"/>

and my json come in like this: Person { ......., "created":"2014-07-19T00:29:09-0300", .... }, but the ng-model on the date stay empty


and when i want to send the date to the server, if i select the 10/10/2014 (dd/MM/yyyy)

it send the data in this way: "2014-10-10T03:00:00.000Z"

and my Controller/DateGson converter its setted to work in this format: new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");


so how to make the date input to display the date in this "yyyy-MM-dd'T'HH:mm:ssZ" format (i just need the day, month and year) and send the edited date in this way to?

i got it working using moment($scope.person.created).format("YYYY-MM-DDTHH:mm:ss-0300"); 


in this case i cant work using this -> 

var pessoa = angular.toJson({
person: $scope.person
});

if i try to set $scope.person.created = moment($scope.person.created).format("YYYY-MM-DDTHH:mm:ss-0300"); 

it work to send, but in the view i got the display like this 

it remove the date previously defined 


i think its because the angular date input cant read in the isoformat



so i end with one "big" question:


is there a way to make it automatically without treating the input(for displaying and sending) , it just receive from the json(in iso format), possible to edit the date, and then return to the server in the same format (iso input)?


sorry bad english, hope you all understand ;)




Tarcisio A.

unread,
Jul 25, 2014, 10:47:09 PM7/25/14
to ang...@googlegroups.com
in the end, this worked for receiving the data: -> 

private final SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.forLanguageTag("BRT"));

if i useyyyy-MM-dd'T'HH:mm:ss.SSSZ (z in the end) the SimpleDateFormat give me error...

now my problem is to make the AngularJS date input to display this date in this pattern: dd/MM/yyyy

Tarcisio A.

unread,
Jul 25, 2014, 10:56:18 PM7/25/14
to ang...@googlegroups.com
partially solved using this pattern:  new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.forLanguageTag("BRT"));





but the problem now is to auto set the Date Input when the ng-model come filled from the requested JSON

Reply all
Reply to author
Forward
0 new messages