Skip to content

Instantly share code, notes, and snippets.

@dshafik
Created February 11, 2012 23:46
Show Gist options
  • Save dshafik/1805158 to your computer and use it in GitHub Desktop.
Save dshafik/1805158 to your computer and use it in GitHub Desktop.
<?php
$interval = DateInterval::createFromDateString("1 hour");
$dateTime->add($interval);
echo $dateTime->format(DateTime::ATOM); // 2012-09-01T23:20:01+01:00
?>
<?php
$timeZone = new DateTimeZone("Europe/London");
$dateTime->setTimezone($timeZone);
echo $dateTime->format(DateTime::ATOM); // 2012-09-01T22:20:01+01:00
?>
<?php
$interval = DateInterval::createFromDateString("1 year 3 months 8 days 2 hours");
$dateTime->add($interval);
echo $dateTime->format(DateTime::ATOM); // 2013-12-10T01:20:01+00:00
?>
object(DateTime)#1 (3) {
["date"]=> string(19) "2012-09-01 16:20:01"
["timezone_type"]=> int(1)
["timezone"]=> string(6) "-05:00"
}
<?php
echo fuzzyDate("2011-09-16T11:38:23-05:00"); // Last Friday at 11:38am
echo fuzzyDate(date(DATE_ATOM)); // Today at 11:18am
echo fuzzyDate("2011-09-21T00:00:00-05:00"); // Tomorrow at midnight
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment