本文介绍了PHP:如何让星期日和星期六给出日期输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得特定日期的星期日和星期六?
How can I get the Sunday and Saturday of the week given a specific date?
例如:
输入:2009年9月28日,星期一
input: Monday, September 28, 2009
输出应为:
2009年9月27日星期日上午12:00 - 2009年10月3日星期六11:59 PM
Sunday, September 27, 2009 12:00 AM - Saturday, October 3, 2009 11:59 PM
我正在考虑使用日期, strtotime , mktime 和 time php函数。
I am thinking of using the date, strtotime, mktime and time php functions.
如果你有一个可用的函数,那么这也是很好的。
If you have a usable function then it is also fine with me.
提前感谢:)
干杯,标记
推荐答案您使用 strtotime( ) 和 date() :
<?php $s = 'Monday, September 28, 2009'; $time = strtotime($s); $start = strtotime('last sunday, 12pm', $time); $end = strtotime('next saturday, 11:59am', $time); $format = 'l, F j, Y g:i A'; $start_day = date($format, $start); $end_day = date($format, $end); header('Content-Type: text/plain'); echo "Input: $s\nOutput: $start_day - $end_day"; ?>输出:
Input: Monday, September 28, 2009 Output: Sunday, September 27, 2009 12:00 PM - Saturday, October 3, 2009 11:59 AM更多推荐
PHP:如何让星期日和星期六给出日期输入?
发布评论