jjzjj

datetime-conversion

全部标签

php - 将秒数和持续时间转换为 SRT(字幕)时间格式 (PHP)

我有这样的输入:start:10|duration:1|text:SubtitleText1start:15|duration:2|text:SubtitleText2start:20|duration:3|text:SubtitleText3这是一个字幕指令集,内容如下:At10secondofthevideo,show"SubtitleText1"for1secondsAt15secondofthevideo,show"SubtitleText2"for2secondsAt20secondofthevideo,show"SubtitleText3"for3seconds这个输入需要

PHP DateTime DateInterval isset 在 var_dump 之后发生变化

此对象中的任何变量都是!isset(),但如果我使用var_dump($interval)或print_r($interval),这些变量将变为isset()。这也适用于empty()/!empty()。所以在下面的代码中$interval->i最初是!isset()但在Ivar_dump($interval)之后是isset()。$future=newDateTime("2018-08-24");$now=newDateTime();$interval=$future->diff($now);if(isset($interval->i)){echo'isset'.$interval-

PHP DateTime 差异返回错误的天数

我有以下代码,它打印出两个日期之间的差异:print_r((newDateTime('2018-01-01'))->diff(newDateTime('2018-11-01')));print_r((newDateTime('2018-10-01'))->diff(newDateTime('2018-11-01')));输出:DateIntervalObject([y]=>0[m]=>10[d]=>0[h]=>0[i]=>0[s]=>0[f]=>0[weekday]=>0[weekday_behavior]=>0[first_last_day_of]=>0[invert]=>0[day

php - 错误 : Object of class DateTime could not be converted to string

我在显示值时遇到错误:$thedate=$row2['date'];echo$thedate;在php中,数据库中的值($thedate)是“2015-05-0521:52:31.000”我如何格式化它才能将其作为字符串显示在php页面上?目前它显示错误“DateTime类的对象无法转换为字符串”。 最佳答案 你有一个DateTime对象,所以你必须使用format()格式化你的输出,例如echo$thedate->format("Y-m-d"); 关于php-错误:Objectofcl

PHP DateTime::createFromFormat 忽略闰年

我必须在日期中转换DayOfYear值。我在2016年的第70天尝试关注:php-r'var_dump(DateTime::createFromFormat("zY","692016"));'classDateTime#1(3){public$date=>string(26)"2016-03-1114:21:07.000000"public$timezone_type=>int(3)public$timezone=>string(3)"UTC"}('z'是基于null的)但这是错误的。应该是2016-03-10!这是一个PHP错误吗? 最佳答案

PHP 手册 : Number Conversion in Is_Numeric Example 1?

我在PHP文档中遇到了这个例子:输出:'42'isnumeric'1337'isnumeric'1337'isnumeric'1337'isnumeric'1337'isnumeric'1337'isnumeric'notnumeric'isNOTnumeric'Array'isNOTnumeric'9.1'isnumeric“42”之后的五个示例的计算结果均为“1337”。我能理解为什么“1337e0”(科学计数法)会这样,但我不明白为什么其他人会这样。我找不到任何人在文档的评论中提到它,我也没有发现它在这里被问到,所以谁能解释为什么'0x539'、'02471'和'0b101001

php - 如何在 Doctrine2 SELECT 查询中处理 DateTime 类型的默认值?

我有以下Doctrine2实体:如你所见,我正在使用GedmoTimestampable与Trait由bundle提供。一切正常。当我获取数据并且updated_at列为NULL0000-00-0000时,问题发生了:00:00。对于这种情况,DateTime对象被转换为一个无效日期,如下所示:‌array('RowId'=>26944,'synchflag'=>1,'updatedAt'=>DateTime::__set_state(array('date'=>'-0001-11-3000:00:00.000000','timezone_type'=>3,'timezone'=>'U

PHP 比较格式为 2011-05-16T09 :39:14+0000 (facebook datetime format) 的两个日期

在PHP中,我想以这种格式比较2个日期:2011-05-16T09:39:14+0000$datedeb="2011-05-18T01:25:18+0000";$datefin="2011-05-16T09:39:14+0000";我有PHP5.1.6供您引用。 最佳答案 您可以使用PHP的strtotime功能。这会将它们转换为时间戳,这意味着您可以像普通数字一样比较它们$datedeb=strtotime("2011-05-18T01:25:18+0000");$datefin=strtotime("2011-05-16T09:

PHP 错误的 DateTime::diff() 返回错误的 DateInterval

我有两个日期时间相差的问题。这是显示DateInterval对象的命令行:php-r"\$a=newDatetime('firstdayof4monthsagomidnight');\$b=newDatetime('firstdayof1monthagomidnight');var_dump(\$a->diff(\$b));"这里是DateInterval输出:classDateInterval#3(15){public$y=>int(0)public$m=>int(3)public$d=>int(3)public$h=>int(0)public$i=>int(0)public$s=>

php - 处理 PHP DateTime 中格式正确但无效的日期

我正在尝试使用PHP的DateTime来验证日期,但DateTime会接受一些格式正确但无效的日期,例如2015-02-30,它将变成March2,2015,没有抛出异常。使用DateTime或其他方法处理此问题有什么建议吗?编辑:谢谢大家的帮助!我是通过捕获异常来处理错误的,但我没有意识到异常只是在错误时抛出,而不是警告,而且这种输入只会引发警告。 最佳答案 使用DateTime::getLastErrors()检查错误。格式正确但无效的日期:$date='2015-02-30';DateTime::createFromForma