草庐IT

DateTime2

全部标签

php - 在 php 中调用未定义的方法 DateTime::add 方法

我正在使用php5.2.9作为xampp安装的一部分。我正在为我的网络应用程序使用codeigniter框架。当我调用DateTime::add时,显示了Calltoundefinedmethod错误。我的代码是...$date_now=newDateTime();$formatted_date=$date_now->format('Y-m-dH:i:s');$expiry_date=$date_now->add(newDateInterval('P1Y'));显示的错误是...Fatalerror:CalltoundefinedmethodDateTime::add()inC:\we

php 101 DateTime 使用 atom 格式

我正在尝试使用DateTime类以DateTime::ATOM格式输出当前时间。我什至不确定我是否正确使用它。或者我是否必须导入一个库或者打开一个wampphp模块。我收到“语法错误,意外的T_NEW”错误代码如下:?> 最佳答案 您可以像这样使用DateTime:$time=newDateTime;echo$time->format(DateTime::ATOM);构造函数(newDateTime)需要您为其创建对象的时间,此时格式并不重要.您在输出时间时指定格式。话虽如此,您遇到的错误似乎无关紧要,可能与该特定行没有任何关系。

php - DateTime 修改当年第一天的字符串

我正在寻找一年中第一天(现在是2011年1月1日)的DateTime修改字符串。我尝试了以下方法:modify('firstdayofthismonth');echo$time->format('c')."\n";//thisdoesn'twork.Ialsotriedseveralotherways$time->modify('firstdayofjanuary');echo$time->format('c')."\n";>我知道还有其他方法可以检索日期,但我在字符串中搜索DateTime->modify()没有其他解决方案。 最佳答案

php - joomla 安装新语言 DateTime::__construct(): 解析时间字符串失败 (jerror)

我是全新安装的Joomla3.1,在我的家用电脑上运行。我的环境是带有apache服务器的Ubuntu12.10,安装了php5.4.6。自安装系统以来,不,我只是尝试通过语言管理器安装更多语言:如您所见,我想要的另外2种语言显示在列表中,但在选择每种语言并单击“安装”后,我被引导到一个包含以下消息的页面:DateTime::__construct():Failedtoparsetimestring(jerror)atposition0(j):Thetimezonecouldnotbefoundinthedatabase只需一个按钮即可返回到控制面板。看到这些语言出现在列表中,我感到很

php DateTime createFromFormat 功能

您好,我似乎无法让日期时间方法按预期工作?我可能做错了什么?//PassesOK$dateTime=DateTime::createFromFormat('d/m/Y','12/12/2012');var_dump($dateTime);//shouldfailbutreturns-2016-09-25$dateTime=DateTime::createFromFormat('d/m/Y','56/56/2012');var_dump($dateTime);//correctlyreturnsFalse$dateTime=DateTime::createFromFormat('d/m/

php - IntlDateFormatter::format():datefmt_format:采用数组或整数时间戳值或 DateTime 对象 (SonataSanBox)

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭7年前。Improvethisquestion我已经安装了SonataAdminBundle。一切正常,但是当我从仪表板添加任何用户时,它会发出警告:Warning:IntlDateFormatter::format():datefmt_format:takeseitheranarrayoranin

PHP:比较两个具有不同时区的 DateTime 对象

PHP如何比较DateTime使用条件运算符时的对象(、>、>=、)?这个比较时区不变吗?我试过下面的代码,看起来它是时区不变的,有人可以确认吗?代码:$datestr="2015-10-0910:28:01";$dt=newDateTime($datestr);$nowdate=newDateTime("now",newDateTimeZone("CET"));print_r($dt);echo"";print_r($nowdate);echo"";var_dump($nowdate输出:DateTimeObject([date]=>2015-10-0910:28:01[timezo

php - 如何使用 DateTime 在 PHP 中获取后天?

我有一个Eloquent查询,目前看起来像这样:$rides=Ride::where('date','>=',new\DateTime('today'))->where('date','get();效果很好,我的问题是,我该如何格式化它:$rides=Ride::where('date','>=',new\DateTime('tomorrow'))->where('date','get();这意味着我正在尝试查找日期介于明天和后天之间的结果。任何帮助将不胜感激。 最佳答案 如果你想得到后天可以使用:new\DateTime('tom

php - 使 DateTime::createFromFormat() 返回子类而不是父类

我正在扩展DateTime,添加一些有用的方法和常量。当使用new创建一个新对象时,一切都很好,但是当使用静态方法createFromFormat时,它总是返回原始的DateTime对象并且当然没有任何子方法可用。我正在使用以下代码来规避此问题。这是最好的方法吗?namespaceNoiseLabs\DateTime;classDateTimeextends\DateTime{staticpublicfunctioncreateFromFormat($format,$time){$ext_dt=newself();$ext_dt->setTimestamp(parent::create

PHP DateTime::Diff 弄错了吗?

DateTime::Diff应计算适当的时间间隔并考虑夏令时(DST)和闰年。虽然显然不是这样。恐怖代码:$d1=newDateTime("2011-10-3001:05:00",newDateTimeZone("Europe/Stockholm"));$d2=newDateTime("2011-10-3003:05:00",newDateTimeZone("Europe/Stockholm"));echo$d1->getOffset()/(60*60);打印“2”!因此请记住,前一天的UTC时间=1h-2h=23:05:00。echo$d2->getOffset()/(60*60);