Apostol5
Apostol5

Reputation: 11

Any PHP class that produces local time for a particular city of the world respecting DST changes?

Is there a PHP(-MySQL) script (/class) that produces local time for a particular city of the world respecting DST changes.

Upvotes: 1

Views: 70

Answers (1)

Andrew Moore
Andrew Moore

Reputation: 95424

You can create a DateTime object representing the local time for any valid ISO-3166-1 timezone identifier.

$bigAppleTime = new DateTime("now", new DateTimeZone("America/New_York"));
echo "It is currently " . $bigAppleTime->format('r') . " in New York city";

You can get a list of valid identifiers and the current time at each by doing the following:

$timezones = DateTimeZone::listIdentifiers();

foreach($timezones as $zone) {
  $time = new DateTime("now", new DateTimeZone($zone));
  printf("% 35s: %s\n", $zone, $time->format('r'));
}

Upvotes: 2

Related Questions