SHARE
TWEET

"DateTime->modify('+0 days')" Modifies DateTime Object

a guest Aug 22nd, 2012 173 Never
  1. <?php
  2.   $tz = new DateTimeZone('Europe/Berlin');
  3.  
  4.   echo "FROM TIMESTAMP, NO TZ:\n";
  5.  
  6.   $date = new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST'));
  7.   echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
  8.  
  9.   $date->modify('+0 days');
  10.   echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
  11.  
  12.   echo "FROM TIMESTAMP, WITH TZ:\n";
  13.  
  14.   $date = new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST'));
  15.   $date->setTimezone($tz);
  16.   echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
  17.  
  18.   $date->modify('+0 days');
  19.   echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
  20.  
  21.   echo "FROM STRING:\n";
  22.  
  23.   $date = new DateTime('2012-08-22 00:00:00 CEST', $tz);
  24.   echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
  25.  
  26.   $date->modify('+0 days');
  27.   echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
  28. ?>
RAW Paste Data
Top