草庐IT

datetime2

全部标签

PHP `DateTime::days` 返回垃圾?

PHP类DateInterval有一个属性“days”。根据手册,它返回“间隔跨越的总天数。如果这是未知的,天数将为假。”在我的例子中,代码:$d=newDateInterval('P1Y');echo$d->days;返回-99999和这样的代码$a=DateTime::createFromFormat("d.m.Y","01.01.2010");$b=DateTime::createFromFormat("d.m.Y","03.01.2010");$d=$b->diff($a);echo$d->days;返回6015我是不是误会了什么? 最佳答案

PHP DateTime 对象 - 时间戳和时区冲突

我有兴趣从DateTime对象获取不同时区的时间。如DateTime::setTimezone中所述doc,当从字符串创建DateTime对象时,这非常有效:$date=newDateTime('2000-01-01',newDateTimeZone('Pacific/Nauru'));echo$date->format('Y-m-dH:i:sP')."\n";$date->setTimezone(newDateTimeZone('Pacific/Chatham'));echo$date->format('Y-m-dH:i:sP')."\n";$date->setTimezone(ne

php - Doctrine 2 : Can't update DateTime column on SQL Server 2008apm

我在apache服务器上使用Doctrine2.2和php5.3。到目前为止,我偶然发现了以下问题:当我尝试更新日期时间列时,我得到:SQLSTATE[22007]:[Microsoft][SQLServerNativeClient10.0][SQLServer]从字符串转换日期和/或时间时转换失败。到目前为止,我什至已经进入专栏,然后使用它只添加了1天来设置新日期......相同的结果。当我改为将数据库和实体中的列从datetime更改为date时,它​​会按预期运行。我的主要问题是,有几个字段需要使用日期时间列。这是我的代码:(生日是我更改为日期的列......并且是少数几个对我来

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