草庐IT

charged_datetime

全部标签

php - 如何在不改变其值的情况下修改原始 DateTime 对象?

我正在尝试使用OOP方式获取当前日期/时间,如下所示:$now=new\DateTime();//2015-05-2411:21:36->thisworksfine我还向同一个对象$now添加了1周,所以我这样做了:$expireTime=$now->modify('+1week');//2015-05-3111:21:36->thisalsoworksfine如果我这样做,用同样的方法:echo$now;//Output:2015-05-3111:28:59//Gotwrongvalue,shouldbeoriginaldatewithoutmodificationecho$expi

php - Laravel 与 SQL Server 2008 抛出 "Conversion of a varchar data type to a datetime data type resulted in an out-of-range value"

我在SQLServer2008中使用laravel4.1我创建了一个基于Eloquentorm的带有时间戳的模型:classAttendanceextends\Eloquent{protected$table='Attendance';publicfunctionusers(){return$this->belongsToMany('User','Users_Attendance','user_id','attendance_id');}}当我尝试插入新字段时:publicfunctionpostAttendanceUsers(){$attendance=newAttendance;$

php - 为什么 php datetime diff 取决于时区?

请看下面的代码:functionprintDiff($tz){$d1=newDateTime("2015-06-01",newDateTimeZone($tz));$d2=newDateTime("2015-07-01",newDateTimeZone($tz));$diff=$d1->diff($d2);print($diff->format("Year:%YMonth:%MDay:%D").PHP_EOL);}printDiff("UTC");printDiff("Australia/Melbourne");结果是:Year:00Month:01Day:00Year:00Month

php - 无法理解 PHP 中 DateTime 类的行为

我在Kubuntu14.04和PHP5.6.23中使用LAMP。使用DateTime时在以下情况下:1.print_r((newDateTime('2016-02-31'))->format('M/d/Y'));//Mar/02/2016(noerrors,why?)2.print_r((newDateTime('2016-02-32'))->format('M/d/Y'));//Error-DateTime::__construct():Failedtoparsetimestring-//(2016-02-32)atposition9(2):Unexpectedcharacter为什

PHP DateTime::createFromFormat 行为

今天,\DateTime::createFromFormat函数的行为让我感到困惑。在我的例子中,我有一个字符串,代表以下格式的日期m/Y(05/2017)。当我想将字符串转换为DateTime对象时,我遇到了以下问题:$date=\DateTime::createFromFormat('m/Y','02/2017');当我转储$date变量时,里面的日期属性是'2017-03-0311:06:36.000000'但是如果我在月份之前添加日期$date=\DateTime::createFromFormat('d/m/Y','01/02/2017');我会得到一个对象具有正确的日期属性

php - PHP DateTime::RFC3339_EXTENDED 损坏了吗?

我似乎无法让DateTime::createFromFormat()在PHP7.0.26中工作我的代码date_default_timezone_set('America/New_York');$t='2018-02-23T11:29:16.434Z';echo'$t:'.json_encode($t).PHP_EOL;$f=DateTime::RFC3339_EXTENDED;echo'$f:'.json_encode($f).PHP_EOL;echo'createFromFormat:'.json_encode(DateTime::createFromFormat($f,$t)).

php - Doctrine 修改后的 DateTime 不会持久化

这个问题在这里已经有了答案:Doctrine2ORMdoesnotsavechangestoaDateTimefield(3个答案)关闭5年前。我尝试用modify函数修改对象的DateTime字段$em=$this->getDoctrine()->getManager();$end=$session->getEndDate();$session->setEndDate($end->modify('+10seconds'));$em->persist($session);$em->flush();这是Session类中$endDate字段的setter:/***@param\DateT

php - 解析 Stripe_Charge Stripe Payments 的输出

以下输出是调用var_export($charge)的结果;如何从$charge访问'paid'=>true的输出?任何想法将不胜感激。我已经尝试过$charge->_values->paid、$charge->paid等。我没有任何运气。我也尝试过$charge['_values']['paid'];Stripe_Charge::__set_state(array('_apiKey'=>'sk_test_BPZyFpcAM','_values'=>array('id'=>'ch_102kMF29T6','object'=>'charge','created'=>1381688,'li

php - 碳 : diff two datetime objects by dates only

假设我有以下代码:$now=Carbon::now();$dateTimeObject=Carbon::parse('2017-07-2010:16:34');如何在忽略时间因素的情况下获取仅之间的差异?因此,如果$now是2017-07-2709:11:12,并且$dateTimeObject中的日期是2017-07-20--差异将是7。我需要它来确保特定操作的结果每天只在数据库中存储一次。注意:我尝试了diffInDays()方法,但如果值为例如,它返回02016-10-1223:56:43和2016-10-1302:01:53-所以,接近午夜和晚上。

php - Eclipse PDT : "<class> cannot be resolved to a type" for default php classes like DateTime, 异常等

在最近的一些Eclipse更新和工作区更改之后,我发现在PDT中验证我的PHP代码时存在一些问题。在为我的项目重新添加所有外部库后,每个外部类都是可解析的,但对于“DateTime”或“Exception”等PHP基类,我收到错误/注释“DateTime无法解析为类型”。PHP验证版本设置为7.1,但更低的设置会产生错误。我该如何解决这个验证问题? 最佳答案 这里有很多种可能的情况;我的是一个相当老的项目,构建路径配置有问题。但是使用GUI我无法修复它。在eclipse关闭时将以下行添加到项目文件夹中的.buildpath文件,然后