如何找出特定时间在特定位置的时区?

时间:2022-10-21 12:54:16

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).

该地点使用的时区是CET(标准时间)或CEST(夏令时)。

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

什么是最简单的方法来检测哪一个在发挥作用?

2 个解决方案

#1


3  

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').

我不太清楚你在问什么。我认为你需要知道的是一个特定的日期是否在夏时制。如果是,您可以使用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...

如果你不需要这些,请说明你需要什么……

#2


1  

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()函数将提供您想要的信息,尽管我不完全确定它是否能够区分标准/夏季时间。

date_default_timezone_get()

函数()

#1


3  

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').

我不太清楚你在问什么。我认为你需要知道的是一个特定的日期是否在夏时制。如果是,您可以使用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...

如果你不需要这些,请说明你需要什么……

#2


1  

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()函数将提供您想要的信息,尽管我不完全确定它是否能够区分标准/夏季时间。

date_default_timezone_get()

函数()