g00fy- / angular-datepicker

calendar and datepicker directives for angular
MIT License
719 stars 420 forks source link

Date format during output #315

Open jcloutz opened 7 years ago

jcloutz commented 7 years ago

I am having a problem with this module. When selecting a date on an empty field it works fine.

If I select Date Dec 22, 2016 will format to 12-22-16 in the field and "Thu Dec 22 2016 00:00:00 GMT-0500 (EST)" in the scope.

If I pre-propulate the field with ng-model and value "Thu Dec 22 2016 00:00:00 GMT-0500 (EST)" the module won't read the date and format the string. It just outputs as Thu Dec 22 2016 00:00:00 GMT-0500 (EST)

If i try to pre-populate the field with this format "2016-12-08T05:00:00.000Z" it works fine, but the datepicker won't output that format.

<input type="text" date-time timezone="UTC" min-view="date" format="M-d-yy" 
max-view="date" placeholder="Start Date" ng-model="request.expected_start_date">

In the photo the field on the left if selected and working properly. The field on the right is pre populated with data that was created by the field previously but won't format it when bound with ng-model. screen shot 2016-12-09 at 5 01 33 pm

DanTalash commented 7 years ago

This module expects to be provided a moment object, which will be updated as the user selects new dates. If you pass a non-moment object such as a string, then the module will attempt to parse it using moment.js and turn it into a moment object.

Therefore, if you need to display the selected dates in a specific format in your scope, you should use the moment().format(); function to get an appropriately formatted string to display.