草庐IT

dateTime

全部标签

php - 带负时间戳的 datetime php fatal error

试图解析1942年5月5日-872726549DatTime::__construct()Failedtoparsetimestring(-872726549)atposition7(4):Unexpectedcharacter111970之前的所有日期都相同1969年12月31日有同样的错误我在windows上使用xampp,php5.4这会触发错误:$topv=-872726549;$compared_time=newDateTime($topv); 最佳答案 根据文档,您应该这样做:$topv='1930-08-09';$co

php - Doctrine2 从特征中复制属性和方法

我有一个实体,我想在其中使用特征“TimestampableEntity”来映射一些属性:namespaceWbudowie\PortalBundle\Entity;useDoctrine\ORM\MappingasORM;useGedmo\Mapping\AnnotationasGedmo;useWbudowie\PortalBundle\Traits\TimestampableEntity;/***Category**@Gedmo\Tree(type="materializedPath")*@Gedmo\SoftDeleteable(fieldName="deletedAt",ti

PHP。为什么日期对象 diff on month 在 12 个月后重置为 0?

今天是2015-07-08。当我运行以下命令时,它返回0。它不应该返回12吗?日期是12个月前。同样,如果$date='2014-06-03',它会返回1。不应该是13吗?最近12个月内的所有日期均已正确计算。$date='2014-07-03';$datetime1=newDateTime(date('Y-m-01',strtotime($date)));$datetime2=newDateTime(date('Y-m-d'));$interval=$datetime1->diff($datetime2);$months_ago=$interval->format('%m');ech

PHP 和系统日期不同

我在系统和PHP之间得到不同的日期/时间。系统:$dateTueNov319:16:51EAT2015PHP:echodate("DMjG:i:sTY");->TueNov316:16:23UTC2015即使系统具有不同的时区,PHP似乎默认为UTC。如何让PHP选择系统日期/时间?注意:出于维护原因,我避免对时区进行硬编码。谢谢。 最佳答案 在PHP中似乎没有简单的(系统无关的)方法来获取系统日期/时间,但这似乎有效:$timezone='UTC';if(strtoupper(substr(PHP_OS,0,3))==='WIN'

javascript - Laravel 时间戳格式/JavaScript 日期

我环顾四周,但未能找到以特定格式返回Laravel时间戳/日期时间的明确方法。它如何保存在数据库中对我来说并不重要,但是当我提取数据时,我想格式化它以便它可以被JavaScript解析。有人知道不需要创建多个访问器的好方法吗?编辑:为了添加更多细节,我实际上使用的是AngularJS,并且希望以一种格式返回日期,以便Angular及其日期过滤器可以理解它。在当前格式下,日期过滤器不起作用,因为据我所知,它无法解析日期。 最佳答案 要定义访问器,请在您的模型上创建一个getFooAttribute方法,其中Foo是您希望访问的列的“驼

php - 无法在 Laravel 5 中将 Carbon 日期设置为 null

我的迁移中有一列dateTime,Laravel将其假定为Carbon。列名是terminado_em并且可以为null。我已经使用我的模型设置了一个Carbon值。现在,当我想将terminado_em设置为null时:publicfunctionreiniciar(){$this->terminado_em=null;...}我得到了错误InvalidArgumentExceptioninCarbon.phpline425:Datamissing当Carbon属性已经设置为Carbon值时,如何将它设置为null? 最佳答案 我

php - 更新 Google 日历 - fatal error : Call to undefined function dateTime()

我正在尝试使用PHPAPI更新Google日历。我已成功创建Google日历事件并自动获取事件ID,但是当我尝试更新事件时,出现此错误:PHPFatalerror:CalltoundefinedfunctiondateTime()inpublic_html/googleapi/calendarupdate.phponline45.它指的是行:$event->setStart.dateTime($startdatetime);这是我当前的错误PHP代码:setAssertionCredentials($credentials);if($client->getAuth()->isAcces

php - 无法转换属性路径 : Expected a\DateTime or\DateTimeInterface 的值

首先:我对Symfony/编程还很陌生,在找到我需要的解决方案时遇到了问题。我的“事件”实体中有这些变量,带有标准的getter和setter。:/***@var\DateTime**@ORM\Column(name="startTime",type="time",nullable=true)**@Assert\Expression(*"this.getStartTime()=this.getStartTime()",*message="Endtimeshouldbegreaterorequaltostarttime!"*)*/private$endTime;我的表单有这个Contro

PHP Carbon diffInMonths

我对PHPCarbondiffInMonths函数有疑问。在某些情况下,我得到了错误的结果。例如:$start=\Carbon\Carbon::create(2017,4,1);$end=\Carbon\Carbon::create(2017,5,1);echo$start->diffInMonths($end);我应该得到1,但我得到了0。我使用PHP7.1和Laravel5.4。有人遇到同样的问题吗?我该如何解决?感谢您的帮助! 最佳答案 $start=\Carbon\Carbon::create(2017,4,1);$end=

php - 计算两个日期之间超过 1 小时的天数再加 1 天

我在获取确切的天数时遇到了问题。鉴于我有日期/时间考虑小时计算代码下面的天数给我零天$fisrstDate=newDateTime("2018-03-0704:46:00");$secondDate=newDateTime("2018-03-0711:10:00");$days=$fisrstDate->diff($secondDate)->days;另一个例子是它应该给我2天但只显示1天我的想法是当超过24小时我想再添加1天这样它会给我2天的输出$fisrstDate=newDateTime("2018-03-0704:46:00");$secondDate=newDateTime(