You can save a specific timestamp value using a predefined format. So let's assume that you have defined your datetime field in the backend as INTEGER, and you want to save it as an integer. You can set this behavior as
public function behaviors() { return [ 'timestamp' => [ 'class' => TimestampBehavior::className(), 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => 'creation_time', ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time', ], 'value' => function() { return date('U');
You can configure yii \ i18n \ formatter to control your global date formats to display for your locale. You can set something like this in your configuration file, with which you can access through
'formatter' => [ 'class' => 'yii\i18n\Formatter', 'dateFormat' => 'php:dm-Y', 'datetimeFormat' => 'php:dmY H:i a', 'timeFormat' => 'php:H:i A', 'defaultTimeZone' OR 'timeZone' => 'Asia/Calcutta',
Read this link and also Doc .
We hope for his work.
source share