Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out timezone of specific datetime in specific location?

Tags:

timezone

php

I have dates of events in another country which I need to save in database. Problem is that those dates have no timezone information included.

Timezone used in this location is CET (standard time) or CEST (summer time).

What is the easiest way to detect which one is in play?

like image 906
Alexei Tenitski Avatar asked Dec 22 '11 20:12

Alexei Tenitski


2 Answers

I'm not quite sure what you're asking. I think what you need to find out is whether a particular date is in daylight savings or not. If so, you can use date('I').

$dst_now = date('I'); // whether our current timezone is currently in DST
$dst_then = date('I', strtotime($date)); // whether that date is in DST for our current timezone

$date_obj = new DateTime($date, new DateTimeZone('Europe/Paris'));
$dst_thereandthen = $date_obj->format('I');
// whether that date is in DST for that timezone

If what you need is none of these, please clarify what you do need...

like image 190
lonesomeday Avatar answered Oct 29 '22 08:10

lonesomeday


I would assume the date_default_timezone_get() function would give you the information you want, though I'm not completely sure it can differentiate between the standard/summer time.

date_default_timezone_get()

like image 40
Kodlee Yin Avatar answered Oct 29 '22 09:10

Kodlee Yin