DateTime ကလပ်စ်၏ setTimezone မန်သို

setTimezone မန်သိုသည် DateTime အတွက်အရာဝတ္ထု၏ အချိန်ဇုန်ကို ပြောင်းလဲပေးပါသည်။ ပါရာမီတာအဖြစ် DateTimeZone ကလပ်စ်၏ အတွက်အရာဝတ္ထုတစ်ခုကို လက်ခံပါသည်။ ပြုပြင်မွမ်းမံထားသော DateTime အတွက်အရာဝတ္ထုကို ပြန်ပေးပါသည်။

သဒ္ဒါ

phppublic DateTime::setTimezone(DateTimeZone $timezone): DateTime

ဥပမာ

လက်ရှိရက်စွဲအတွက် 'America/New_York' အချိန်ဇုန်ကို သတ်မှတ်ကြပါစို့:

php<?php
  $date = new DateTime('now', new DateTimeZone('UTC'));
  $date->setTimezone(new DateTimeZone('America/New_York'));
  echo $date->format('Y-m-d H:i:s');
?>

ကုဒ်ကို လုပ်ဆောင်ခြင်း၏ ရလဒ်:

php'2023-11-15 10:30:00'

ဥပမာ

ရှိပြီးသား DateTime အတွက်အရာဝတ္ထု၏ အချိန်ဇုန်ကို ပြောင်းလဲကြပါစို့:

php<?php
  $date = new DateTime('2023-01-01 12:00:00', new DateTimeZone('Europe/Moscow'));
  $date->setTimezone(new DateTimeZone('Asia/Tokyo'));
  echo $date->format('Y-m-d H:i:s');
?>

ကုဒ်ကို လုပ်ဆောင်ခြင်း၏ ရလဒ်:

php'2023-01-01 18:00:00'

ဤအကြောင်းကိုလည်း ကြည့်ပါ

  • date ဖန်ရှင်ကို,
    အကြောင်းမှာ ရက်စွဲ/အချိန်ကို ပုံစံချပေးပါသည်
  • date_default_timezone_set ဖန်ရှင်ကို,
    အကြောင်းမှာ ပုံသေ အချိန်ဇုန်ကို သတ်မှတ်ပေးပါသည်
  • DateTimeZone ကလပ်စ်ကို,
    အကြောင်းမှာ အချိန်ဇုန်ကို ကိုယ်စားပြုပါသည်