Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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:转换日期时间字符串VCALENDAR接受格式_Php - Fatal编程技术网

PHP:转换日期时间字符串VCALENDAR接受格式

PHP:转换日期时间字符串VCALENDAR接受格式,php,Php,我将日期时间字符串转换为2015年8月18日星期二07:20:00 GMT 0530(IST),并希望转换为VCALENDAR接受的格式为20150818T125000Z 欢迎提供任何帮助。您可以这样做: $str = "Tue Aug 18 2015 07:20:00 GMT 0530 (IST)"; // remove the part after GMT $str = substr($str,0,-11); // create date from string $date = date_c

我将日期时间字符串转换为
2015年8月18日星期二07:20:00 GMT 0530(IST)
,并希望转换为
VCALENDAR
接受的格式为
20150818T125000Z


欢迎提供任何帮助。

您可以这样做:

$str = "Tue Aug 18 2015 07:20:00 GMT 0530 (IST)";
// remove the part after GMT
$str = substr($str,0,-11);
// create date from string
$date = date_create($str);
// IST (Indian Standard Time) = Asia/Kolkata
$zone = new DateTimeZone('Asia/Kolkata');
// set timezone
date_timezone_set($date,$zone);
// output formatted date
$vcal = $date->format("Ymd\THis\Z");
echo $vcal;
输出为:

20150818T125000Z

谢谢你的简短回答