我正在尝试使用一组规则返回日期字符串,但无法使用http://php.net/manual/en/function.date.php
来确定如何设置它我所要做的就是:
两个回报的格式均为dd/mm/yyyy
(例如2016年3月31日)
答案 0 :(得分:1)
这应该有效:
<?php
echo date('d/m/Y', strtotime('next Wednesday',strtotime("-1 week +11 hours +30 minutes")));
?>
编辑它,我认为是一小时。这是2个测试用例:
<?php
echo date('d/m/Y', strtotime('next Wednesday',strtotime("-1 week +11 hours +30 minutes",strtotime('4/5/2016 12:29'))));
echo PHP_EOL;
echo date('d/m/Y', strtotime('next Wednesday',strtotime("-1 week +11 hours +30 minutes",strtotime('4/5/2016 12:30'))));
?>
尝试阅读更多日期函数和strtotime / strftime,它们都有很好的用途。
答案 1 :(得分:1)
这应该这样做。如果这对你有用,请告诉我。
<?php
date_default_timezone_set('Europe/London');
date_default_timezone_get();
$timenow = date("H:i");
$daynow = date("l");
$time = "12:30";
$day = "Tuesday";
$otherday = array("Saturday", "Sunday", "Monday");
if (($daynow == $day) && ($timenow > $time)) {
echo "Its's $day $timenow after $time and next $day will be at: " . date('Y-n-d', strtotime('next Wednesday')) . "" ;
} elseif (($daynow == $day) && ($timenow < $time)) {
echo "Its's $day $timenow before $time and last $day was at : " . date('Y-n-d', strtotime('pevious Wednesday')) . "" ;
} elseif (in_array($daynow, $otherday)) {
echo "Its's $daynow $timenow before $day $time and last $day was at: " . date('Y-n-d', strtotime('pevious Wednesday')) . "";
} else {
echo "Its's $daynow $timenow after $day $time and next $day will be at: " . date('Y-n-d', strtotime('next Wednesday')) . "";
}
?>
如果您的服务器上的所有内容都已正确设置,您也可以修剪一些部分,例如date_default_timezone_set('Europe/London');
或date_default_timezone_get();
。