How to change Timezone?

Sometimes we need to convert time from one timezone to another. so best thing is to save the time in UTC/GMT and then convert it back to required timezone by php.
E.g If we have to send email to users according to their selected time , then first we will save the user time to UTC/GMT and his timezone in the database. and when we are sending emails by running cron jobs or whatever, we will convert the time from user timezone to server timezone and check if the time is same.

This is a Simple Solution for it.

   function converToTz($time="",$toTz='',$fromTz=''){	
      // timezone by php friendly values
      $date = new DateTime($time, new DateTimeZone($fromTz));
      $date->setTimezone(new DateTimeZone($toTz));
      $time= $date->format('Y-m-d H:i:s');
      return $time;
   }
Categories: Developer Notes
Strict Standards: Only variables should be passed by reference in /home/elisegxm/public_html/wp-content/themes/eliseinfotech/functions.php on line 62

Strict Standards: Only variables should be assigned by reference in /home/elisegxm/public_html/wp-content/themes/eliseinfotech/functions.php on line 62
| Comments