2

In my project am getting a date like this "05/23/2016" format. But i want to show it in the view like this "23 May 2016" using Angular.

How to do it ? Please help...

Kishan
  • 340
  • 2
  • 6
  • 28

4 Answers4

1

Create a date object out of your string (in your controller, for example):

$scope.dateVar = new Date("05/23/2016");

and then use the date filter in your template:

{{ dateVar | date:'dd MMMM yyyy' }}
evsheino
  • 1,669
  • 13
  • 18
1

First split the string "05/23/2016" on "/".

$scope.today = "05/23/2016";
$scope.date = $scope.today.split("/");

Then convert your string date into Date object

$scope.actualdate = new Date($scope.date[2],$scope.date[0] - 1,$scope.date[1]);

Now you can use any combination of the date filter from AngularJS docs

{{actualdate | date: 'dd MMMM yyyy'}} // 23 May 2016
{{actualdate | date: 'yyyy dd MMMM'}} // 2016 23 May
{{actualdate | date: 'dd MMMM'}} // 23 May

You can use any combination and format the date as you want.

EXAMPLE FIDDLE

Nishant123
  • 1,938
  • 2
  • 21
  • 42
0

If You want to use angularjs to change the format , use $filter

$filter('date')(date, format, timezone)

refer to this link https://docs.angularjs.org/api/ng/filter/date

Thanks

Ujjwal kaushik
  • 1,486
  • 9
  • 17
0

Use Angular date filter

Before applying filter you date must be in Javascript Date format or in date timestamp.