Formatting date returned in REST


I’m trying to return UTC date with my REST API, to have it like that: “2015-04-25 16:01:59Z”. Is there any easy way to configure Yii to use Formatter when returning data with REST?


Not sure if I understood your question correct?

But sure, there are plenty ways to format data in any application.

Setup Data Formatter:

Or a afterfind function in model:

public function afterFind(){


	// Format attributes like ever you want to receive them

	$this->created_at = date('d.m.Y - H:i:s', $this->created_at);

	$this->updated_at = date('d.m.Y - H:i:s', $this->updated_at);

	// You could also format the data with the yii data formatter here... 



Hope this helps?


I was looking for some way that I can do that with config for whole dates across all models in my API. After checking Yii2 code I know already that it’s not possible, and your solution is easiest to do, even if that means to change that across whole models.

Thank you :)