Ich habe ein Datum Feld Termin als datetime
Feld in MySQL Db konfiguriert.yii2: Formatierung des Datums für die Anzeige
In meinem Modell Appointment.php Regeln sind wie folgt festgelegt:
public function rules()
{
return [
[['appointment_date','weekdays'], 'safe'],
[['appointment_date'], 'date','format' => 'd-M-yyyy H:m'],
und in web.php unter Komponente habe ich
gesetzt'formatter' => [
'defaultTimeZone' => 'UTC',
'timeZone' => 'Asia/Kolkata',
und meiner Meinung nach mir das zu formatieren versuchen Datum für die Anzeige wie folgt aus:
[
Yii::$app->formatter->asDatetime('appointment_date')
],
Jetzt bekomme ich den Fehler -
appointment_date' is not a valid date time value: DateTime::__construct(): Failed to parse time string (appointment_date) at position 0 (a): The timezone could not be found in the database
Array
(
[warning_count] => 1
[warnings] => Array
(
[6] => Double timezone specification
)
[error_count] => 3
[errors] => Array
(
[0] => The timezone could not be found in the database
[11] => Unexpected character
[12] => Double timezone specification
)
Während das Datum in der Datenbank gespeichert ist, wie: 2015-01-20 11:50:00
Wenn ich nicht das Datum am Formatierung und einfach halten das Attribut in Sicht als appointment_date
dann das Datum als 2015-01-20 11:50:00
ich als 20-01-2015 11:50:00
das Datum angezeigt werden soll gezeigt Wenn ich den Code wie folgt bin mit:
[
'attribute'=>'appointment_date',
'format'=>['DateTime','php:d-m-Y H:i:s']
],
Ich bekomme das Datum korrekt formatiert.
Ich will wissen, was ich bei der Verwendung
Yii::$app->formatter->asDatetime('appointment_date')
Dank
@ fl0r- Ihr Vorschlag ist auch korrekt, aber ich brauche langen Code wie 'Attribut =>' Termin_Datum ',' Wert '=> Yii :: $ App-> Formatierer-> AsDatetime ($ Model-> Termin_Datum) – Pawan