LoginSignup
0
0

More than 1 year has passed since last update.

現在時刻を表示する方法

Last updated at Posted at 2022-03-22

・現在時刻を表示する方法
①構造化プログラミング
コード

date_default_timezone_set('Asia/TOKYO');
echo '現在の時刻は、' . date('G時 i時 s秒') . 'です';

現在時刻を取得するにはdate()を使う。
date_default_timezone_set('Asia/TOKYO')で日本時間を取得するように設定している。
echoで表示するようにして初めて表示される。(date()は時間を返すだけ)

②オブジェクト指向
コード

$today = new DateTime();
$today->setTimezone(new DateTimeZone('Asia/Tokyo'));
echo '現在の時刻は、' . $today->format('G時 i分 s秒');

日本時間の設定方法が異なる。

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