I am trying to 2015年04月17日 12:44:38.0 to dd/MM/yyyy format in angularjs
<td ng-bind="item.MON_FE_DUEDATE | date:'dd-MM-yyyy'"></td>
But still showing 2015年04月17日 12:44:38.0 only.Please suggested to me where is my mistake?
asked Apr 25, 2017 at 8:28
user7052596
1 Answer 1
Because you are trying to format it on a string.
Please see working fiddle.
https://jsfiddle.net/p7gz0opm/
Converted string to Date.
function MyCtrl($scope) {
$scope.date = new Date('2015-04-17 12:44:38.0 ');
}
Template:
<div ng-app ng-controller="MyCtrl">
{{date | date:'dd-MM-yyyy'}}<br />
{{date}}
</div>
Edit :
In your case you will have to pass through a function. Please see another fiddle.
https://jsfiddle.net/qjs1uj37/
$scope.parth=function(str){
return new Date(str);
}
answered Apr 25, 2017 at 8:33
Parth Ghiya
6,9692 gold badges32 silver badges37 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
Giovani Vercauteren
Angular converts valid ISO 8601 to dates automatically. So it can work with strings, they just have to be in a valid format. You have a good answer nonetheless.
Parth Ghiya
@GiovaniVercauteren correct and totally agree, but if u see his answer that is not ISO 8601 format. There's a space in between. It has to be something like 2015年04月17日T12:44:38.0 And thanks :)
Giovani Vercauteren
@j.Doe what you have in your OP works. JSFiddle. You just need to have a correct date.
|
lang-js