fork(1) download
  1. <?php
  2. $utc = "2014-05-29T04:54:30.934Z";
  3.  
  4. $date = new DateTime(date('Y-m-d'), new DateTimeZone('UTC'));
  5. echo 'Original: ', $date->format('r'), PHP_EOL;
  6. // Step 2: Change the timezone to Europe/Rome
  7. $date->setTimezone(new DateTimeZone('Europe/Rome'));
  8.  
  9. echo 'After: ', $date->format('r'), PHP_EOL;
  10.  
  11. $dt = new DateTime($utc);
  12.  
  13. echo 'Original: ', $dt->format('r'), PHP_EOL;
  14.  
  15. $tz = new DateTimeZone('Asia/Kolkata');
  16.  
  17. $dt->setTimezone($tz);
  18. echo 'After setting timezone: ', $dt->format('r'), PHP_EOL;
Success #stdin #stdout 0.03s 26120KB
stdin
Standard input is empty
stdout
Original: Tue, 17 Sep 2024 00:00:00 +0000
After: Tue, 17 Sep 2024 02:00:00 +0200
Original: Thu, 29 May 2014 04:54:30 +0000
After setting timezone: Thu, 29 May 2014 10:24:30 +0530