PHP:如何让星期日和星期六给出日期输入?

编程入门 行业动态 更新时间:2024-10-28 21:15:26
本文介绍了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:如何让星期日和星期六给出日期输入?

本文发布于:2023-05-24 12:36:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:星期日   星期   日期   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!