Roman Holic
Roman Holic

Reputation: 189

PHP strtotime timezone

i have problem with PHP strtotime converting to different timezone. My code is simple:

<?php
date_default_timezone_set("Europe/Bratislava");
echo date("H:i",strtotime("20:00 America/New_York")); 
?>

This code is returning: 02:00. But it should return 14:00.

Can you help me please to fix this?

Upvotes: 0

Views: 947

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503469

This code is returning: 02:00. But it should return 14:00.

No, it's right. You're converting from 8pm in New York (currently UTC-4 due to DST) into the Europe/Bratislava time zone (currently UTC+2 due to DST).

So:

New York:   8pm
UTC:        Midnight
Bratislava: 2am

If you're trying to convert from a Europe/Bratislava time into a New York time, then you need to switch your time zone IDs.

Upvotes: 9

Related Questions