$entry->postDate
will give you the postDate
property of the EntryModel
, which itself is a DateTime
object.
The JSON transformer will do its best to convert that object to JSON by returning its visible properties, which produces the JSON object in your example.
Angular has built-in date filters, but it requires the input data to be in a recognized format. So, what you really want in your JSON - rather than a representation of the whole DateTime
object - is a more primitive value that Angular knows how to interpret as a date: You need a timestamp.
Luckily, you can easily access the timestamp of the PHP DateTime
object in your transformer, like this:
'postDate' => $entry->postDate->getTimestamp() * 1000
(We're multiplying the timestamp by 1000 because Angular wants the timestamp to represent milliseconds; PHP gives us the timestamp in seconds.)
Then, in Angular you can use the date filter to change the format as desired, which in your front-end code would look something like: {{ note.postDate | date:'medium' }}