0

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

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

6 Comments

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.
@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 :)
Can you please give example for using ng-bind ng-bind="item.MON_FE_DUEDATE | date:'dd-MM-yyyy'"
@j.Doe what you have in your OP works. JSFiddle. You just need to have a correct date.
Thanks sir @Giovani Vercauteren
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.