php - Set time zone for strtotime function -


i'm setting daily countdown deadline date. code works fine.

the issue that, according php manual, function use default time zone:

each parameter of function uses default time zone unless time zone specified in parameter.

i need able specify time zone.

the sections i've read in manual not entirely clear how this.

here's code:

<?php  $date = strtotime("september 30, 2016 11:59 pm");  $remaining = $date - time(); // number of seconds remaining  $days_remaining = floor($remaining / 86400);  $hours_remaining = floor(($remaining % 86400) / 3600); // display final 5 days  echo "$days_remaining days remaining";  ?> 

is there simple way integrate pacific time zone code above?

my guess make first line of code:

date_default_timezone_set('america/los_angeles'); 

but i'm not sure work , don't want change time zone other scripts.

i'm open alternative methods achieving goal.

you can capture existing default timezone using date_default_timezone_get()

so save current timezone, set new one, , calc's , replace original timezone this

$save_zone = date_default_timezone_get();  date_default_timezone_set('america/los_angeles');  $date = strtotime("september 30, 2016 11:59 pm"); $remaining = $date - time(); // number of seconds remaining $days_remaining = floor($remaining / 86400); $hours_remaining = floor(($remaining % 86400) / 3600); // display final 5 days echo "$days_remaining days remaining";  date_default_timezone_set($save_zone); 

list of valid timezone settings


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -