Welcome Guest, Not a member yet? Register   Sign In
date helper - converting time AUTO detecting DST

I don't know why is this not done, but this would be good. I googled and finally found the solution.

public function convert_time_auto_dst($system_time, $to_timezone = 'UTC') {

  $php_tz = $this->ci_tz_to_php_tz($to_timezone);

  $tz_obj = new DateTimeZone($php_tz);
   $time_obj = new DateTime($system_time);

  return $time_obj->format("Y-m-d H:i:s");  
  // timestamp of this object is not shifted so if we return it, and use php date function to format it - we would get not converted time


$system_time is the in format which we are using in our application, storing in database.
$to_timezone - is the codeigniter timezone short like UP1, but I have not made full convertion function to php time zones.

You can adjust this to require as parameter PHP time zone. And I return formated time but this also can be adjusted.

Simple function but good, we dont need to manually update daylight saving parameter in database for users. Unlless there are some bugs.

Theme © iAndrew 2016 - Forum software by © MyBB