PHP Datetime`下周星期三`给我星期一 [英] PHP Datetime `next week wednesday` gives me monday

查看:128
本文介绍了PHP Datetime`下周星期三`给我星期一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用新的\DateTime(下周三,周三)获取下周的星期三日期。但是,它返回星期一的 2016-12-19 00:00:00.000000 。为什么会这样呢?如何获得正确的结果?



我试图在线将其复制到PHP沙箱中,但在那里它返回正确的结果

解决方案

似乎是一个错误(可能是这一个仅在周日发生):

 <?php 

var_dump(new \DateTime (下周星期三));

PHP版本5.6.23至5.6.29和7.0.8至7.1.0于12月19日输出(一个星期一),而PHP版本5.0至5.6.22和7.0.0至7.0.7将在12月28日(星期三)返回。



我没有看到任何提及PHP 5.6.23或7.0.8的变更日志条目中的相关更改。


I'm trying to get the next week's Wednesday date using new \DateTime('next week wednesday'). However, it returns 2016-12-19 00:00:00.000000 which is Monday. Why is it so? How to get correct result?

I tried to reproduce it in a PHP sandbox online but there it returns correct result http://sandbox.onlinephpfunctions.com/code/7ab99fcfeffedc1ad01d7de9ed236ac273fe1bb3 Can it be something depending on my environment?

I'm running PHP 7 on OSX

PHP 7.0.11 (cli) (built: Oct 2 2016 00:32:59) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

解决方案

This appears to be a bug (possibly this one that only occurs on Sundays):

<?php

var_dump(new \DateTime('Wednesday next week'));

PHP versions 5.6.23 to 5.6.29 and 7.0.8 to 7.1.0 output December 19 (a Monday), while PHP versions 5.0 to 5.6.22 and 7.0.0 to 7.0.7 return December 28 (a Wednesday).

I don't see any mention of related changes in the changelog entries for PHP 5.6.23 or 7.0.8.

这篇关于PHP Datetime`下周星期三`给我星期一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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