0

我有两个日期字段文本框。在一个字段中,我填充它getDate()返回当前日期。但在另一个表中,我想填充该月的最后一个日期。

例如:

当前日期:9/20/2012在一个文本中。现在,下一个日期必须是9/30/2012

同样,当前日期:01/14/2012在一个文本中。现在下一个日期必须是01/31/2012

4

3 回答 3

1

你可以使用date->modify()

<?php
$date = new DateTime('9/20/2012');
$date->modify('last day of this month');
echo $date->format('m/d/Y'); // 09/30/2012
?>

<?php
$date = new DateTime('10/20/2012');
$date->modify('last day of this month');
echo $date->format('m/d/Y'); // 10/31/2012
?>
于 2013-09-19T23:27:23.673 回答
1

使用 PHP 的DateTime类:

$date = new DateTime('9/20/2012'); 
echo $date->format('m/t/Y'); // t returns no. of days in a month

输出:

09/30/2012

演示!

于 2013-09-19T23:16:00.513 回答
0

尝试这个:

function daysInMonth(month,year) {
  var dd = new Date(year, month, 0);
  return dd.getDate();
}
于 2013-09-19T23:11:14.937 回答