正しいタイムゾーンで日付を表示する方法は?
コンテンツタイプに日時範囲フィールド(field_date)があります。コンテンツタイプを作成したら、開始日を次のように設定します。 2017-02-27 19:30:01 ここで、値を取得して日付を他の形式で表示したいので、次のコードを使用してみてください。 // Loading the node. $node = Node::load(2100); // Getting the start date value. $date = $node->field_date->value; // Printing to see what is the output. dpm($node->field_date->value); $date = strtotime($date); // Printing my timezone. dpm(drupal_get_user_timezone()); // Applying my custom format. $date = \Drupal::service('date.formatter')->format($date, 'custom', 'Y-m-d H:i:s', drupal_get_user_timezone()); // …