0

我想计算一个月的天数。它出现了这个警告:

cal_days_in_month() [function.cal-days-in-month]: invalid date. 

任何人都可以帮助我。:

$numberofday = new DateTime($month);
$numberofday = cal_days_in_month(CAL_GREGORIAN, $month,$year1);
$Total=$length  x 24  x $numberofday ; 
4

3 回答 3

0

$月 = 4;

$year1 = 2013;

$numberofday = cal_days_in_month(CAL_GREGORIAN, $month,$year1);

回声 $numberofday; //30

于 2013-07-16T02:02:41.003 回答
0

你有'长度',应该是 $length 吗?

于 2013-07-16T01:34:34.793 回答
0

cal_days_in_month()接受月份字段的整数值,请将月份转换为整数:

$month = "april";
$year1 = "2013";
$month = date('m', strtotime($month));

在使用该功能之前。

$numberofday = cal_days_in_month(CAL_GREGORIAN, $month, $year1);

替代品cal_days_in_month

$month = "april";
$year1 = "2013";
$numberofday = date('t', strtotime("$year1-" . date("m",strtotime($month)) . "-01"));

还:

$Total=$length  x 24  x $numberofday;

应该:

$Total=$length * 24 * $numberofday;
于 2013-07-16T01:30:25.747 回答