Installation
The preferred way to install this extension is through composer., (*1)
Either run, (*2)
php composer.phar require --prefer-dist maddoger/yii2-datetime-behavior "*"
or add, (*3)
"maddoger/yii2-datetime-behavior": "*"
to the require section of your composer.json
file., (*4)
Usage
For datetime format and timezone conversation you can use DateTimeBehavior
., (*5)
In model behaviors for timestamp field:, (*6)
[
'class' => DateTimeBehavior::className(),
'attributes' => ['published_at'],
'originalFormat' => 'U', //original format
'originalTimeZone' => 'UTC', //original timezone
'timeZone' => 'Europe/London', //local timezone
'format' => 'datetime', //local format, Formatter format
]
Now you can use published_at
as original attribute and published_at_local
as user read-write attribute., (*7)
For date fields:, (*8)
[
'class' => DateTimeBehavior::className(),
'attributes' => ['birth_date'],
'originalFormat' => 'Y-m-d',
'format' => 'date',
'timeZone' => 'UTC',
]