dave
dave

Reputation: 1679

php timezone displaying correct hours but not seconds and minutes

I want to display the time in different timezones, so i m using this

$date=new DateTime(null, new DateTimeZone('America/Los_Angeles')); echo $date->format('Y-m-d H:i:sP') . "\n";
$date=new DateTime(null, new DateTimeZone('Europe/Paris')); echo $date->format('Y-m-d H:i:sP') . "\n";

So the above code display the correct hours but it's displaying the minutes and seconds same for all the timezone.

Please help

Thanks in advance Dave

Upvotes: 1

Views: 237

Answers (2)

Khez
Khez

Reputation: 10350

Either your example is wrong or your understanding of timezones is. Seconds don't change across timezones. In some small cases minutes change by varying amounts (check the list at the bottom). In the majority of cases, it changes by hours. In all of these cases by extent, the day may change too.

<?php
$date=new DateTime(null, new DateTimeZone('America/Los_Angeles'));
echo $date->format('Y-m-d H:i:s P') . "\n";// -07:00
$date=new DateTime(null, new DateTimeZone('Europe/Paris'));
echo $date->format('Y-m-d H:i:s P') . "\n";// +02:00
$date=new DateTime(null, new DateTimeZone('America/Caracas'));
echo $date->format('Y-m-d H:i:s P') . "\n";// -04:30
?>

Minutes actually change by 20, 24, 25, 30, 40, 44, 45, 51

Upvotes: 2

S L
S L

Reputation: 14328

Because the difference of time is 9 hrs 0 minutes.

Paris
Los Angels

Upvotes: 3

Related Questions