Get which day of the week the month starts on for given input

爱⌒轻易说出口 提交于 2019-12-13 09:31:12

问题


I have a function which defines what day of the week the month starts on for the current month:

public function firstDayOfMonth()
    {
        $day =  (int) date("w", strtotime(date('m').'/01/'.date('Y').' 00:00:00'));
        return $day;
    }

How would I alter the above, in a way that allows me to get the day of the week the month starts on if I give it input, for example 'June'.


回答1:


public function firstDayOfMonth($month) {
    $day =  (int) date("w", strtotime($month . ' 01,' . date('Y') . ' 00:00:00'));
    return $day;
}



回答2:


You can simplify your code to this:

$month = 'June';
$day = (int) date('w', strtotime($month));


来源:https://stackoverflow.com/questions/10517035/get-which-day-of-the-week-the-month-starts-on-for-given-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!