Created
February 4, 2020 10:15
-
-
Save thephucit/e2d9c7c24947d95c4428c4cb946ec89d to your computer and use it in GitHub Desktop.
Convert datetime in db into local datetime
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 | |
| /** | |
| * Convert datetime in db into local datetime | |
| * @param string $datetime | |
| * @param string $format | |
| * @param string $timezone | |
| * @return String | |
| */ | |
| public static function convert_datetime_to_local($datetime, $format = 'H:i d-m-Y', $timezone = 'Asia/Ho_Chi_Minh') | |
| { | |
| $userTimezone = new \DateTimeZone($timezone); | |
| $gmtTimezone = new \DateTimeZone('UTC'); | |
| $myDateTime = new \DateTime($datetime, $gmtTimezone); | |
| $offset = $userTimezone->getOffset($myDateTime); | |
| $myInterval = \DateInterval::createFromDateString((string) $offset . 'seconds'); | |
| $myDateTime->add($myInterval); | |
| return $myDateTime->format($format); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
format in js: HH:mm DD:MM:YYYY