Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Time in PST

Tags:

timezone

php

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

like image 889
Zach Smith Avatar asked Jun 15 '10 18:06

Zach Smith


People also ask

What UTC is PST?

Pacific Standard Time (PST) is UTC-8:00, and Pacific Daylight Time (PDT) is UTC-7:00, this time zone is called the Pacific Time Zone (PT) in the United States and Canada.


2 Answers

Well, the easiest might be:

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

Take a look at supported timezones to find one suitable for your needs.

like image 84
Tatu Ulmanen Avatar answered Sep 21 '22 19:09

Tatu Ulmanen


Let's try a solution that uses PHP's modern date handling. This example requires PHP 5.2 or better.

// Right now it's 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"
like image 22
Charles Avatar answered Sep 25 '22 19:09

Charles