PHP - RFC3339 日期为“友好”日期(谷歌日历 API)

发布于 2024-10-05 15:58:44 字数 151 浏览 1 评论 0 原文

我需要将日期从 RFC3339 格式(由 google calendar api 返回)转换为 PHP 中的“10 月 1 日下午 5 点”等格式。

如果我是正确的,RFC3339 的格式是:2010-12-01T17:00:00.000-02:00

谢谢

I need to convert a date from RFC3339 format (that is returned by google calendar api) to a format such as "1st October, 5pm" in PHP.

If I am correct, format for RFC3339 is: 2010-12-01T17:00:00.000-02:00

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞取 2024-10-12 15:58:44

使用 PHP 令人惊叹的 strtotime日期 函数。

$RFC = "2010-12-01T17:00:00.000-02:00";
$date = date('jS F, ga', strtotime($RFC)); // 1st December, 5pm

更新:如果您的 PHP >= 5.2,您可以使用 DateTime 类。

$RFC = "2010-12-01T17:00:00.000-02:00";
$date = new DateTime($RFC);
$dateStr = $date->format('jS F, ga'); // 1st December, 5pm

Use PHP's amazing strtotime and date functions.

$RFC = "2010-12-01T17:00:00.000-02:00";
$date = date('jS F, ga', strtotime($RFC)); // 1st December, 5pm

UPDATE: If you have PHP >= 5.2, you can use the DateTime class.

$RFC = "2010-12-01T17:00:00.000-02:00";
$date = new DateTime($RFC);
$dateStr = $date->format('jS F, ga'); // 1st December, 5pm
捎一片雪花 2024-10-12 15:58:44

使用 strtotime() 转换为 UNIX 时间戳。然后 date() 格式化输出

Use strtotime() to convert to a UNIX timestamp. Then date() to format the output

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文