如何获取一月是几号到几号?

aolon 2003-12-25 09:07:06
本月是从几号到几号.
然后是上一月,大上月,大大上月......
和下一月,大下月,大大下月......
...全文
110 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yicikou 2003-12-25
  • 打赏
  • 举报
回复
$month = 12; //指定的月
$year = 2003; //指定的年

echo "1号到".date("t",mktime(0,0,0,$month,1,$year))."号";
xuzuning 2003-12-25
  • 打赏
  • 举报
回复
每个月都从1号开始,这有例外吗?

<?php
$month = 12;//指定的月
$year = 2003; //指定的年
echo "1号到".date("d",mktime(0,0,0,$month+1,0,$year))."号";
?>
patchclass 2003-12-25
  • 打赏
  • 举报
回复
1,3,5,7,8,10,12
31天
2月 按是否闰年算
其余的30 天,不是很简单吗,最基础的编程问题
狂派 2003-12-25
  • 打赏
  • 举报
回复
<?php
/* This calendar is not very pretty as-is, but it is functional and fast.
Formatting to suit your needs should be fairly simple.

The latest version of this calendar is formatted much more niceley. It
also includes a full-featured "Community Calendar" which is linked to a
MySQL database for reporting upcoming events.

The latest copy of the calendar can be viewed and/or downloaded from:
http://modems.rosenet.net/mysql/ */

/* Set some variables */
$date=01;
$day=01;
$off=0;

/* The month and year variables can (should) be passed from a preceding
web page rather than hard coded */
if ($month=="")
{
$month=date(n);
}
if ($month<=0 or $month>=13)
{
$month++;
}
if ($year=="") $year = date(Y);

/* Figure out how many days are in this month */
while (checkdate($month,$date,$year)):
$date++;
endwhile;

/* Create a table with days of the week headers */
echo "<div>$year 年 $month 月</div>";
echo "<table border='1' cellpaddig='5' cellspacing='5' width='100%'><tr>";
echo "<th><b><font face='Arial'>星期日</font></b></th>";
echo "<th><b><font face='Arial'>星期一</font></b></th>";
echo "<th><b><font face='Arial'>星期二</font></b></th>";
echo "<th><b><font face='Arial'>星期三</font></b></th>";
echo "<th><b><font face='Arial'>星期四</font></b></th>";
echo "<th><b><font face='Arial'>星期五</font></b></th>";
echo "<th><b><font face='Arial'>星期六</font></b></th>";

/* Start the table data and make sure the number of days does not exceed
the total for the month - $date will always be one more than the total
number of days in the momth */
echo "<tr>";
while ($day<$date):

/* Figure what day of the week the first falls on and set the number of
preceding and trailing cells accordingly */
if ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) == 'Sunday') {
echo "<td>$day</td>";
$off = '01';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==
'Monday') {
echo "<td></td><td>$day</td>";
$off= '02';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==
'Tuesday') {
echo "<td></td><td></td><td>$day</td>";
$off= '03';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==
'Wednesday') {
echo "<td></td><td></td><td></td><td>$day</td>";
$off= '04';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==
'Thursday') {
echo "<td></td><td></td><td></td><td></td><td>$day</td>";
$off= '05';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==
'Friday') {
echo "<td></td><td></td><td></td><td></td><td></td><td>$day</td>";
$off= '06';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) ==
'Saturday') {
echo "<td></td><td></td><td></td><td></td><td></td><td></td><td>$day</td>";
$off= '07';
}
else {
echo "<td>$day</td>";
}

/* Increment the day and increment the cells that go before the end of the row
and end the row when appropriate */
$day++;
$off++;

if ($off>7) {
echo "</tr><tr>";
$off='01';
} else {
echo "";
}

endwhile;

echo "</table>";

$back_month=intval($month)-1;
$back_year=intval($year)-1;
echo "
<p>
<div>
<a href=\"$PHP_SELF?month=$back_month\">上个月</a>
</div>
";

/*
This script was created by Rosenet, Inc. 1998. Feel free to use and modify it.
If you use this script, please do not alter or remove this comment section.
http://www.rosenet.net/
http://modems.rosenet.net/
http://modems.rosenet.net/mysql/
*/
?>
wuliangxia 2003-12-25
  • 打赏
  • 举报
回复
我只知道,每个月都是从1号开始的.
最后一天,有个老兄告诉过我,将下月1日减一日就是了.

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧