Convert data from email header

前端 未结 1 954
孤独总比滥情好
孤独总比滥情好 2021-02-09 09:43

Does anyone could help me how to convert data from email header?

I have the next date format from email header: Wed, 28 Apr 2010 21:59:49 -0400

I ne

相关标签:
1条回答
  • 2021-02-09 10:01

    You should be using DateTime for this, specifically DateTime::createFromFormat():

    $str = 'Wed, 28 Apr 2010 21:59:49 -0400';
    $date = DateTime::createFromFormat( 'D, d M Y H:i:s O', $str);
    

    Now, you have a Date object in $date, and you can grab the unix timestamp (if that's what you want), or you can format it into a date for MySQL.

    echo $date->getTimestamp(); // Outputs: 1272506389
    echo $date->format( 'Y-m-d H:i:s'); // For MySQL column, 2010-04-28 21:59:49
    

    You can see it working in the demo.

    0 讨论(0)
提交回复
热议问题