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