PHP:如何获得星期天和星期六定一个日期输入? [英] PHP: How to get Sunday and Saturday given a date input?

查看:143
本文介绍了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

Sunday, September 27, 2009 12:00 AM - Saturday, October 3, 2009 11:59 PM

我想使用的strtotime mktime 时间 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() 日期( )

<?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:如何获得星期天和星期六定一个日期输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆