Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

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

By: a guest on Aug 22nd, 2012  |  syntax: PHP  |  size: 0.92 KB  |  views: 149  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. ?>
clone this paste RAW Paste Data