use yii\behaviors\TimestampBehavior; public function behaviors() { return [ TimestampBehavior::class, ]; }
use yii\behaviors\TimestampBehavior; public function behaviors() { return [ [ 'class' => TimestampBehavior::class, 'createdAtAttribute' => 'created_time', 'updatedAtAttribute' => 'updated_time', 'value' => function() { return time(); }, ], ]; }This code specifies that the "created_time" and "updated_time" attributes should be automatically set to the current UNIX timestamp when a model is created or updated. The TimestampBehavior class is part of the Yii core package and does not require any additional package libraries to use.