mktime()最多期望6个参数,其中7个在

时间:2018-12-07 11:24:00

标签: php parameters phpmyadmin expect mktime

代码:

$morningstarts = 9;
$eveningends   = 22;
$dst_change = is_dst($month,$day,$year);
$am7=mktime($morningstarts,0,0,$month,$day,$year,is_dst($month,$day,$year,$morningstarts));
$pm7=mktime($eveningends,$eveningends_minutes,0,$month,$day,$year,is_dst($month,$day,$year,$eveningends));

该代码在PHP 5.6上运行良好,但是在PHP 7.1中,我遇到以下错误。

  

警告:mktime()最多期望6个参数,其中7个是

请任何人帮助我。

2 个答案:

答案 0 :(得分:0)

您需要删除对mktime的调用中的第7个参数,并用date_default_timezone_set设置您的时区,然后PHP将为您处理夏令时。例如

date_default_timezone_set('Asia/Karachi');
$morningstarts = 9;
$eveningends   = 22;
$am7=mktime($morningstarts,0,0,$month,$day,$year);
$pm7=mktime($eveningends,$eveningends_minutes,0,$month,$day,$year);

答案 1 :(得分:0)

    $timezone = 'America/Chicago';
    $morningstarts = 9;
    $eveningends = 22;
    $am7 = new \DateTime("@" . mktime($morningstarts, 0, 0, $month, $day, $year));
    $pm7 = new \DateTime("@" . mktime($eveningends, $eveningends_minutes, 0, $month, $day, $year));
    $am7->setTimeZone(new \DateTimeZone($timezone));
    $pm7->setTimeZone(new \DateTimeZone($timezone));