dpv21589 2015-11-02 21:59
浏览 89
已采纳

PHP imap在纪元时间从电子邮件中获取日期

It's not as easy as strtotime()...

I'm returning dates of emails with php imap. When I return a date, I get this formatting:

21 May 2015 20:48:36 -0400
Fri, 15 May 2015 00:13:12 +0000
Fri, 7 Aug 2015 07:11:42 -0400 (EDT)
Fri, 4 Sep 2015 11:03:15 -0400
Mon, 10 Aug 2015 22:04:10 +0000
Tue, 14 Jul 2015 12:54:47 -0400
Sun, 21 Jun 2015 10:49:06 +0000
Fri, 12 Jun 2015 17:35:26 +0000
Thu, 27 Aug 2015 11:47:55 -0400
Mon, 20 Jul 2015 12:43:45 -0400
Fri, 18 Sep 2015 07:47:04 -0400 (EDT)
etc.

As you can see, the dates aren't exactly consistent. One of the dates does not have a day name (Fri). Some of the dates have an (EDT) tag on it, and the others don't.

I tried using strtotime($date), but I believe that since it has the time zone in some of them, it's messing the date up.

Is there a way to convert these very strange times into epoch time?

  • 写回答

1条回答 默认 最新

  • draw62188 2015-11-02 22:22
    关注

    You could clean up your input before processing it as time strings:

    $input = "21 May 2015 20:48:36 -0400
    Fri, 15 May 2015 00:13:12 +0000
    Fri, 7 Aug 2015 07:11:42 -0400 (EDT)
    Fri, 4 Sep 2015 11:03:15 -0400
    Mon, 10 Aug 2015 22:04:10 +0000
    Tue, 14 Jul 2015 12:54:47 -0400
    Sun, 21 Jun 2015 10:49:06 +0000
    Fri, 12 Jun 2015 17:35:26 +0000
    Thu, 27 Aug 2015 11:47:55 -0400
    Mon, 20 Jul 2015 12:43:45 -0400
    Fri, 18 Sep 2015 07:47:04 -0400 (EDT)";
    
    $output = '';
    
    $lines = explode("
    ", $input);
    
    foreach($lines as $line) {
        $output .= preg_replace('/(\w{3}, )|( \(\w{3}\))/', '', $line)."
    ";
    }
    
    echo $output;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样