PST delivery time

What is the easiest way to display the current time in PST (West Coast) using PHP?

+5
source share
5 answers

Well, the easiest way:

date_default_timezone_set('America/Los_Angeles');
echo date('Y-m-d');

See supported time zones to find the right one for your needs.

+15
source

Try a solution using modern PHP data processing. This example requires PHP 5.2 or better.

// Right now it about four minutes before 1 PM, PST.
$pst = new DateTimeZone('America/Los_Angeles');
$three_hours_ago = new DateTime('-3 hours', $pst); // first argument uses strtotime parsing
echo $three_hours_ago->format('Y-m-d H:i:s'); // "2010-06-15 09:56:36"
+9
source

.

echo date('r');
putenv('TZ=PST');
echo date('r');  
0
source

If you use or have access to Carbon, you can do this:

$timezone = 'America/Los_Angeles';
$now = Carbon::now()->tz($timezone)->toDateTimeString();
echo $now;
0
source

To convert date / time between time zones:

include ("Date.php");
$d = new Date("2010-06-21 10:59:27"); // initialize object
$d->setTZByID("GMT"); // set local time zone
$d->convertTZByID("PST"); // convert to foreign time zone
echo $d->format("%A, %d %B %Y %T"); // retrieve converted date/time
-1
source

All Articles