在 PHP 中输入错误的星期几

Giving wrong day of week in PHP

它显示星期四,但星期三输出,请帮助我修复它......

我的代码

<?php
    date_default_timezone_set('Asia/Kolkata');
    $date = '2017/06/07';
    $weekday = date('l', strtotime($date)); 
    echo $weekday; //
?>

提前致谢

试试这个:

date_default_timezone_set('Asia/Kolkata');
$date = '2017/06/07';
$date = str_replace('/','-', $date);
$weekday = date('l', strtotime($date)); 
echo $weekday;
// Output: Wednesday

Phpfiddle link

Check the document here

Note: Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. If, however, the year is given in a two digit format and the separator is a dash (-, the date string is parsed as y-m-d. To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.

您需要使用日期格式"Y-m-d"才能得到您想要的结果。 $date = '2017/06/07' 表示 2017 年 6 月 7 日。

如果你想获得 2017 年 7 月 6 日,那么更改

$date = '2017/06/07';

$date = '2017/07/06';