MarlonRibunal
MarlonRibunal

Reputation: 4097

PHP Set time to Pacific daylight saving time

In a PHP site, I have the current time setting:

D j M Y, G:ia

How do I change that to reflect current pacific time with the daylight saving time?

Upvotes: 2

Views: 5443

Answers (2)

Paolo Bergantino
Paolo Bergantino

Reputation: 488394

You can use date_default_timezone_set to set the timezone in which all date functions are run. PHP date functions take care of daylight saving time (DST) for you if you just want the current time.

Upvotes: 3

Mantichora
Mantichora

Reputation: 385

date_default_timezone_set('America/Los_Angeles'); // or wherever you are

$time = time();

if ($time >= strtotime("Second Sunday March 0")  && $time < strtotime("First Sunday November 0")) 
{

    echo date('m/d/y h:i a', $time);

} else {

    echo date('m/d/y h:i a', $time);

}

Upvotes: 0

Related Questions