获取带时区的周范围

Get week range with timezone

我正在尝试获取给定日期的周范围。我使用下面的代码来做到这一点。

 /**
 * get week range with timezones. GTM+1 or UTC+1
 * @return array
 */
function get_week_range(){
    $current_date = date('d/m/Y');
    //Add 1 hour to get the right timezone (GMT+1)
    $current_date = date('d/m/Y H:i:s', strtotime($current_date) + 3600);
    

    $week_range = array();
    $week_range['start'] = date('d/m/Y', strtotime('last saturday', strtotime($current_date)));
    $week_range['end'] = date('d/m/Y', strtotime('next saturday', strtotime($current_date)));

    return $week_range;
}

我怎样才能使它工作以考虑时区?我的时区是 GMT+1,但返回的日期有 - 1 小时的差异

您可以使用 date_default_timezone_set()

https://www.php.net/manual/en/function.date-default-timezone-set.php