I have following text input filled by model value in timestamp:
<input type="datetime" ng-model="workerDetail.dateOfBirth" class="form-control" id="date_of_birth" />
It displays value in input as given timestamp.
I would like to convert value which is visible in input into formatted date (YYYY/MM/DD), but in model should be always as timestamp.
I tried to do it by this way:
{{workerDetail.dateOfBirth | date:'MMM'}}
But without luck.
Thanks for any advice.
It is a simple HTML code where the ng-model value of your country format date is changed into some other country format date. Output: Example 2: In the following HTML code snippet, it is shown how to input date from the date picker menu and then express in a given format i.e. yyyy-mm-dd.
To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.
You can try a filter
HTML
<input type="datetime" ng-model="mydateOfBirth" class="form-control" id="date_of_birth" />
Controller JS
$scope.$watch('mydateOfBirth', function (newValue) { $scope.workerDetail.dateOfBirth = $filter('date')(newValue, 'yyyy/MM/dd'); }); $scope.$watch('workerDetail.dateOfBirth', function (newValue) { $scope.mydateOfBirth = $filter('date')(newValue, 'yyyy/MM/dd'); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With