这篇文章主要介绍了php计算指定日期所在周的开始和结束日期的方法,涉及php操作日期时间的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了PHP计算指定日期所在周的开始和结束日期的方法。具体实现方法如下:
<html>
<head>
<title>计算一周开始结束日期</title>
</head>
<body>
<form method="post" action="./index.html" enctype="utf-8">
<table>
<tr><td>输入年份</td>
<td><input name="year" type="text" maxlength="4" /></td>
</tr>
<tr><td>输入月份</td>
<td><input name="month" type="text" maxlength="2" /></td>
</tr>
<tr><td>输入天</td>
<td><input name="day" type="text" maxlength="2" /></td>
</tr>
<tr><td colspan="2"><input type="submit" value="计算" />
</td></tr>
</table>
</form>
<?php
$time= $_POST[year].'-'.$_POST[month].'-'.$_POST[day].' 00:00:00';
echo('你输入的时间是:'.$time.'</br>');
$lastday=date("Y-m-d",strtotime("$time Sunday"));
echo('输入的时间星期第一天是:'.date("Y-m-d",strtotime("$lastday - 6 days")).'<br/>');
echo('输入的时间星期最后一天是:'.$lastday);
?>
</body>
</html>总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
立即学习“PHP免费学习笔记(深入)”;
以上就是PHP计算一周开始结束日期的方法的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号