转换 PHP 中的日期
Converting Date in PHP
我有一个这种格式的日期Thu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time)
,我想将其转换成 PHP 日期格式 Y-m-d
代码如下
$statMonth = 'Thu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time)'
echo date('Y-m', strtotime($statMonth));
returns我1970-01
你能告诉我如何获得月份和年份吗?[=14=]
您需要从日期中删除 (India Standard Time)
,您可以使用以下正则表达式动态删除:
$statMonth = 'Thu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time)';
$statMonth = trim(preg_replace('/\s*\([^)]*\)/', '', $statMonth));
echo date('Y-m', strtotime($statMonth));
我有一个这种格式的日期Thu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time)
,我想将其转换成 PHP 日期格式 Y-m-d
代码如下
$statMonth = 'Thu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time)'
echo date('Y-m', strtotime($statMonth));
returns我1970-01
你能告诉我如何获得月份和年份吗?[=14=]
您需要从日期中删除 (India Standard Time)
,您可以使用以下正则表达式动态删除:
$statMonth = 'Thu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time)';
$statMonth = trim(preg_replace('/\s*\([^)]*\)/', '', $statMonth));
echo date('Y-m', strtotime($statMonth));