0
0

More than 1 year has passed since last update.

WordPressで時間がずれてしまう

Last updated at Posted at 2022-04-27

前提

WordPressでcurlコマンドを使用し外部APIから日時を取得し表示したいが、
時間がずれてしまう、、、
WordPressの管理画面でTimeZoneの設定が出来るらしいが、
筆者はWordPressの設定に詳しくないので
コードを書いて実装したいと思いました。

対処

一般的な記述をすると世界標準時が表示され9時間程ずれる。

date(“Y-m-d H:i:s”);
$hoge = $get_response_data['datetime'];
$timezone_tokyo_hoge = DateTime::createFromFormat('Y-m-d\TH:i:s+',$hoge);
$timezone_tokyo_hoge->setTimezone(new DateTimeZone('Asia/Tokyo'));

echo date_format($timezone_tokyo_hoge,"Y年m月d日 H時i分");

とりあえずこの変数内ではtimezoneの設定が出来ている。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0