duanlan7903
2014-02-20 21:04 阅读 193
已采纳

如何在php中获取带时区的日期/时间

I am trying to get a date in this format using php but i cannot find the correct format.

2014-02-20T12:47:39.444-0700

my current code:

 $MTtime = new DateTime('now', new DateTimeZone('America/Denver'));
 $UTCtime = new DateTime('now', new DateTimeZone('UTC'));
 $MTtime->format('Y-m-d H:i:s');
 $UTCtime->format('Y-m-d H:i:s');

how can I achieve this?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dongxinjun3944 dongxinjun3944 2014-02-27 18:49

    thank you @DaOgre for pointing me to the ATOM time format.

    here is how I finally got it to work:

    $UTCtime = new DateTime('now', new DateTimeZone('UTC'));
    $data['logDateTime'] = $UTCtime->format(DateTime::ATOM);
    
    点赞 评论 复制链接分享
  • douliao7354 douliao7354 2014-02-20 21:14

    Try using gmDate:

    gmDate("Y-m-d\TH:i:s.u-Z");
    

    http://www.php.net/gmdate

    点赞 评论 复制链接分享

相关推荐