V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
66beta
V2EX  ›  PHP

WordPress 和 php.ini 里面都设置了时区为 Asia/Shanghai,但是发出去的邮件时间依然是 0 时区的?

  •  
  •   66beta · 2014-07-31 11:39:26 +08:00 · 3524 次点击
    这是一个创建于 3549 天前的主题,其中的信息可能已经有所发展或是发生改变。
    其实很简单的代码:
    $str = date("H:i:s");
    wp_mail('[email protected]', 'send testing', "This email is from Wordpress send at $str");

    如果直接在页面输出,时区是对的

    问题是用wp_mail发送到gmail后,看到是0时区的时间(这时间只是邮件的正文而已,不是邮件的发送时间~)

    从代码来讲 $str = date("H:i:s"); 每次都获取当前时间,为啥,为啥???
    第 1 条附言  ·  2014-07-31 14:48:45 +08:00
    写插件的时候,需要使用WP自己的函数 current_time("H:i:s");
    http://codex.wordpress.org/Function_Reference/current_time
    4 条回复    2014-07-31 16:00:37 +08:00
    msg7086
        1
    msg7086  
       2014-07-31 13:58:19 +08:00   ❤️ 1
    输出在页面与发邮件是同一个上下文?

    会不会是wp自己改掉了默认时区?
    kmvan
        2
    kmvan  
       2014-07-31 14:19:24 +08:00 via Android   ❤️ 1
    直接用mail时间有没错?
    66beta
        3
    66beta  
    OP
       2014-07-31 14:48:39 +08:00
    @msg7086 @kmvan
    我擦,是WP的插件系统的设定问题

    写插件的时候,需要使用WP自己的函数 current_time("H:i:s");
    http://codex.wordpress.org/Function_Reference/current_time
    msg7086
        4
    msg7086  
       2014-07-31 16:00:37 +08:00
    "In WordPress, PHP's time() will always return UTC"

    看来猜对了。我觉得你应该能猜到像WP这样的系统在初始化的时候会reset掉各种东西。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1017 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:33 · PVG 03:33 · LAX 12:33 · JFK 15:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.