Created
June 4, 2019 15:57
-
-
Save amnuts/d329a04a9a6a4ecb5426f62810571e2a to your computer and use it in GitHub Desktop.
PHP date/time conversion example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach (range(1, 12) as $m) { | |
$elStart = new \DateTimeImmutable("2019-{$m}-10 23:50:00", new \DateTimeZone('Europe/London')); | |
$elEnd = $elStart->add(new \DateInterval('PT5H')); | |
$utcStart = $elStart->setTimezone(new \DateTimeZone('UTC')); | |
$utcEnd = $elEnd->setTimezone(new \DateTimeZone('UTC')); | |
printf("E/L: %s / %s, UTC: %s / %s\n", | |
$elStart->format(DATE_RFC822), | |
$elEnd->format(DATE_RFC822), | |
$utcStart->format(DATE_RFC822), | |
$utcEnd->format(DATE_RFC822) | |
); | |
} | |
/* | |
* | |
Outputs | |
E/L: Thu, 10 Jan 19 23:50:00 +0000 / Fri, 11 Jan 19 04:50:00 +0000, UTC: Thu, 10 Jan 19 23:50:00 +0000 / Fri, 11 Jan 19 04:50:00 +0000 | |
E/L: Sun, 10 Feb 19 23:50:00 +0000 / Mon, 11 Feb 19 04:50:00 +0000, UTC: Sun, 10 Feb 19 23:50:00 +0000 / Mon, 11 Feb 19 04:50:00 +0000 | |
E/L: Sun, 10 Mar 19 23:50:00 +0000 / Mon, 11 Mar 19 04:50:00 +0000, UTC: Sun, 10 Mar 19 23:50:00 +0000 / Mon, 11 Mar 19 04:50:00 +0000 | |
E/L: Wed, 10 Apr 19 23:50:00 +0100 / Thu, 11 Apr 19 04:50:00 +0100, UTC: Wed, 10 Apr 19 22:50:00 +0000 / Thu, 11 Apr 19 03:50:00 +0000 | |
E/L: Fri, 10 May 19 23:50:00 +0100 / Sat, 11 May 19 04:50:00 +0100, UTC: Fri, 10 May 19 22:50:00 +0000 / Sat, 11 May 19 03:50:00 +0000 | |
E/L: Mon, 10 Jun 19 23:50:00 +0100 / Tue, 11 Jun 19 04:50:00 +0100, UTC: Mon, 10 Jun 19 22:50:00 +0000 / Tue, 11 Jun 19 03:50:00 +0000 | |
E/L: Wed, 10 Jul 19 23:50:00 +0100 / Thu, 11 Jul 19 04:50:00 +0100, UTC: Wed, 10 Jul 19 22:50:00 +0000 / Thu, 11 Jul 19 03:50:00 +0000 | |
E/L: Sat, 10 Aug 19 23:50:00 +0100 / Sun, 11 Aug 19 04:50:00 +0100, UTC: Sat, 10 Aug 19 22:50:00 +0000 / Sun, 11 Aug 19 03:50:00 +0000 | |
E/L: Tue, 10 Sep 19 23:50:00 +0100 / Wed, 11 Sep 19 04:50:00 +0100, UTC: Tue, 10 Sep 19 22:50:00 +0000 / Wed, 11 Sep 19 03:50:00 +0000 | |
E/L: Thu, 10 Oct 19 23:50:00 +0100 / Fri, 11 Oct 19 04:50:00 +0100, UTC: Thu, 10 Oct 19 22:50:00 +0000 / Fri, 11 Oct 19 03:50:00 +0000 | |
E/L: Sun, 10 Nov 19 23:50:00 +0000 / Mon, 11 Nov 19 04:50:00 +0000, UTC: Sun, 10 Nov 19 23:50:00 +0000 / Mon, 11 Nov 19 04:50:00 +0000 | |
E/L: Tue, 10 Dec 19 23:50:00 +0000 / Wed, 11 Dec 19 04:50:00 +0000, UTC: Tue, 10 Dec 19 23:50:00 +0000 / Wed, 11 Dec 19 04:50:00 +0000 | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment