bashirudeen ahmad bashirudeen ahmad - 6 months ago 49
AngularJS Question

AngularJS change date format( JUN, Wednesday ) from Wed Jun 08 2016 05:30:00 GMT+0530 (India Standard Time)

I want to change date format from Wed Jun 08 2016 05:30:00 GMT+0530 (India Standard Time) to JUN, Wednesday.

I have tried,

<p data-ng-bind = "'Wed Jun 08 2016 05:30:00 GMT+0530 (India Standard Time)'| date:'MMM' "></p>


I did not get the exact result(JUN, Wednesday), please help.

Answer

Your problem is your trying to cast a string with date format. So, You need to cast first string to date, then move the hour for the timezone problem, finally apply the filter.

In your controller you must do something like:

# Step 0: Get a date from your string 
var date = new Date('Wed Jun 08 2016 05:30:00 GMT+0530'); 
# Step 1: From the date move, for the Timezones problems.
$scope.date = new Date(date.valueOf() + date.getTimezoneOffset() * 60000);`

Then, in your view you can use {{ date | date:'MMM-EEEE' }}

You can check in this Plnkr: http://plnkr.co/edit/zselhzgL4njIWEXxTWh6?p=preview