methuselah methuselah - 6 months ago 20
AngularJS Question

Convert date in UK format and Django format to real date

I am trying to convert

booking.date
, which is in the following format
01/06/2016
to the format
'EEEE, MMMM d, y' (Wednesday, June, 1, 2016)
. I've tried the following AngularJS filter date but it doesn't seem to be working. Any suggestions?

<p style="small">{{ booking.date | date:'fullDate' }}<br>{{ booking.time }}</p>


I also have another date in the format:
2016-05-31T19:18:24Z
elsewhere, is there another approach I can take for this as well?

Answer

You need to convert the date string into a Date() object before submitting into the date filter.

// in controller
booking.date = new Date(booking.date);

// template can remain same
<p>{{booking.date | date:'fullDate'}}</p>

// test code 
console.log($filter('date')(new Date('2016-05-31T19:18:24Z'), 'fullDate'));