简体   繁体   中英

angular.ui DatePicker how to set the Date format?

I am using the angular.ui DatePicker

http://angular-ui.github.io/bootstrap/#/datepicker

In the doc it says:

"Everything is formatted using the date filter and thus is also localized."

I am having a hard time figuring out how to use the date filter to control the date format set in the model.

Using the DatePicker I am getting a date format set in the model like this:

"2013-09-07T03:18:43.000Z"

However, I am trying to serialize with Grails, and I want my date format to be like this:

"2013-09-07T03:18:43Z"

How do I configure the DatePicker to output this format of date? Or since it is a JavaScript date, do I have to do this at the server side? Ultimately, I would like to send:

"2013-09-07T03:18:43Z"

in a JSON put to the server.

TIA

You can follow this trademark way of parsing the default ISO date format to your own format stripping out the milliseconds, in client side.

Or, in the server side (Grails) you can parse the string to your own format as below:

Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "2013-09-07T03:18:43.000Z")
    .format("yyyy-MM-dd'T'HH:mm:ss'Z'") 

//prints "2013-09-07T03:18:43Z"

If you are persisting a Date instead of a String , just use Date.parse(..) (without .format ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM