Created
June 13, 2018 05:05
-
-
Save edutrul/030fc7f225446f5d3167a342c9e8dd79 to your computer and use it in GitHub Desktop.
Deal with dates in php and drupal 7
This file contains hidden or 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 | |
// Title: Convert to correct timezone. | |
// Set default time. | |
$date = new DateTime('2018-05-17 22:29:00', new DateTimeZone('UTC')); | |
print $date->format('Y-m-d H:i:s') . "\n"; // 2018-05-17 22:29:00 | |
// Now convert to correct timestamp. | |
$date->setTimezone(new DateTimeZone('Australia/Brisbane')); | |
print $date->format('Y-m-d H:i:s') . "\n"; // 2018-05-18 08:29:00 | |
// ---------------------------------------------------------------- | |
// The same as above but drupalway(using DateObject from date contrib module in drupal7). | |
$date = new DateObject('2018-05-17 22:29:00', new DateTimeZone('UTC')); | |
$date->setTimezone(new DateTimeZone('Australia/Brisbane')); | |
print $date->format('d/m/Y h:i:s'); // 2018-05-18 08:29:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment