Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. <?php
  2.  
  3. function convert_to_timezone($date, $format, $timezone) {
  4. $object = date_create_from_format($format, $date, timezone_open('UTC'));
  5. date_timezone_set($object, timezone_open($timezone));
  6.  
  7. return $object;
  8. }
  9.  
  10. function convert_to_timezone_string($date, $timezone) {
  11. $format = 'Y-m-d H:i:s';
  12. return date_format(convert_to_timezone($date, $format, $timezone), $format);
  13. }
  14.  
  15.  
  16. $date = '2016-02-10 19:25:00';
  17.  
  18. echo convert_to_timezone_string($date, 'America/Sao_Paulo') . "\n";
  19. echo convert_to_timezone_string($date, 'America/Los_Angeles') . "\n";
  20. echo convert_to_timezone_string($date, 'Europe/London') . "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement