Issue in yii2 timezone formatter -
in php.ini timezone utc. system timezone utc. yii defaulttimezone utc. datetime attribute gets converted timezone "asia/kolkata" before saving db.
eg: utc time 12:00hrs input 17.30hrs expect in db 12:00hrs , in view 17.30hrs got in db 17:30hrs , in view got 23:00hrs.
web.php:
'formatter' => [ 'class' => 'yii\i18n\formatter', 'dateformat' => 'php:d-m-y', 'datetimeformat' => 'php:d-m-y h:i a', 'timeformat' => 'php:h:i a', 'timezone' => 'asia/kolkata', ],
you can choose save specific timestamp value using predefined format. let's take have defined datetime field in backend integer , want save integer. can set behavior this
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'); // unix timestamp }, ], ]; }
you can configure yii\i18n\formatter control global date formats display locale. can set in config file can access across
'formatter' => [ 'class' => 'yii\i18n\formatter', 'dateformat' => 'php:d-m-y', 'datetimeformat' => 'php:d-m-y h:i a', 'timeformat' => 'php:h:i a', 'defaulttimezone' or 'timezone' => 'asia/calcutta', //global date formats display locale. ],
hope works.
Comments
Post a Comment