Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中将日期转换为ISO 8601时出错,并删除毫秒_Php_Date Formatting_Iso8601 - Fatal编程技术网

在PHP中将日期转换为ISO 8601时出错,并删除毫秒

在PHP中将日期转换为ISO 8601时出错,并删除毫秒,php,date-formatting,iso8601,Php,Date Formatting,Iso8601,我正在用PHP处理一个日期输入,我正在转换为ISO 8601,这很好。它工作正常,但我需要删除以毫秒为单位的最后一个字符 要转换为ISO 8601的PHP代码 //Getting the timezone date_default_timezone_set('Africa/Nairobi'); //CONVERTING TO ISO 8601 $newDate = date('c', strtotime('+24 hours')); dd($newDate); //Output after

我正在用PHP处理一个日期输入,我正在转换为ISO 8601,这很好。它工作正常,但我需要删除以毫秒为单位的最后一个字符

要转换为ISO 8601的PHP代码

//Getting the timezone
date_default_timezone_set('Africa/Nairobi');

//CONVERTING TO ISO 8601
$newDate = date('c', strtotime('+24 hours'));
dd($newDate);

//Output after dd
2018-10-25T14:34:44+03:00
我需要删除
+03:00
,这样输出将是
2018-10-25T14:34:44

子字符串如何

substr(date('c',strtotime('+24 hours')),0,-6)
或者,仅根据需要设置格式:

date('Y-m-d\TH:i:s',strtotime('+24 hours'))

如果不需要时区(那些不是毫秒),那么不要使用包含时区的日期格式。使用来获得正确的格式,而不是操纵不同的格式。所以我想你并不真正想要ISQ8601,即你想要的不是你要求的。并且+03:00不是毫秒,它是从“Z”偏移的。阅读@John Conde,,它不是重复的,,我需要删除最后的字符,这是一个与另一个不同的问题。@YvesLeBorg好的,,,我如何删除它,,我正在使用该日期格式访问一个需要严格format@Patweb是的。你只想改变日期的格式,这个问题解释了如何做。基本上,不要使用
c
格式化程序。