doushajian2018 2009-06-18 23:06
浏览 12
已采纳

哪个php日期和时间工具用于GMT抵消

It appears there are many ways to approach date and time massaging in php. I usually am only every dealing with local time. Today, I need to work in UTC.

I am querying against an API, the data they give me about an arbitrary record is: created: Thu, 18 Jun 2009 21:44:49 +0000 * Documented as 'UTC record creation time'

utc_offset: -28800 * Difference between users re

I need to convert that to a simple string to show the user what time and date the data was submitted in their local time.

I believe, the above translates to, if in Calif. for example: Thursday 18th of June 2009 02:44:49 PM

My goal is to get to a time value I can pass to date() for easy formatting in a "pretty" format.

Is it really as simple as converting the above created time to seconds from epoch, adding in the offset, and then passing that to date()? Any gothcha's to look out for?

$created_time = 'Thu, 18 Jun 2009 21:44:49 +0000';
$utc_offset = -28800;
$seconds = strtotime($created_time);
$localized_time = $seconds + $utc_offset;

echo date(DATE_RFC822, $localized_time);

Thanks

  • 写回答

2条回答 默认 最新

  • dsfs504545 2009-06-18 23:10
    关注

    PHP should do thing automatically for you. I can also HIGHLY recommend using the DateTime object instead.

    $dt = new DateTime($created_time); echo $dt->format(DATE_RFC2822);

    PHP's date and time functions are timezone aware.. Make sure you're on a recent version of PHP, because a lot of work has been done in improving these systems.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊