dongtuo1482 2015-10-15 07:33
浏览 26
已采纳

用PHP转换日期[重复]

This question already has an answer here:

I have a date in this formatThu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time) and I want to convert this in to PHP date format Y-m-d

Code is as follows

$statMonth = 'Thu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time)'
echo date('Y-m', strtotime($statMonth));

returns me 1970-01

Can you please let me know how to get Month and Year.

</div>
  • 写回答

1条回答 默认 最新

  • dongwan5381 2015-10-15 07:51
    关注

    You need to remove (India Standard Time) from your date, You can use following regex to remove dynamically:

    $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));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan