atluriajith
atluriajith

Reputation: 792

How do I get the timezone from a string containing a datetime value in PHP?

Given the following string: 2011/09/18 11:59PM EDT, 2011-09-18T23:59:59+00:00

How do I extract the timezone part from this string using PHP?

Upvotes: 3

Views: 6122

Answers (1)

Jon
Jon

Reputation: 437386

Create a new DateTime object from the string, and use getTimezone on it to get the timezone:

$time = '2011/09/18 11:59PM EDT';
$dt = new DateTime($time);
print_r($dt->getTimezone()->getName());

See it in action.

Upvotes: 12

Related Questions