PHP 中 ATOM 日期格式转换为 UNIX

发布于 2024-08-24 19:57:52 字数 182 浏览 2 评论 0原文

我需要在 PHP 中将提要日期/时间转换为 unix 时间戳。

来自 2010-04-13T10:00:00.000-04:00 -> Unix

我一直在使用 date()strtotime() 尝试各种奇怪的事情,但没有成功。

I need a feed date/time converted into a unix timestamp in PHP.

from 2010-04-13T10:00:00.000-04:00 -> Unix

I have been trying all sorts of weird things with date() and strtotime() with no luck.

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

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

发布评论

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

评论(2

执笏见 2024-08-31 19:57:52
$dt=new DateTime("2010-04-13T10:00:00.000-04:00");
echo $dt->format('U');
$dt=new DateTime("2010-04-13T10:00:00.000-04:00");
echo $dt->format('U');
绝影如岚 2024-08-31 19:57:52

试试这个:

$time = strtotime(preg_replace('/(T|\.\d{3})/', ' ', '2010-04-13T10:00:00.000-04:00'));

这里我使用 preg_replaceT 和毫秒替换为单个空格。

Try this:

$time = strtotime(preg_replace('/(T|\.\d{3})/', ' ', '2010-04-13T10:00:00.000-04:00'));

Here I used preg_replace to replace the T and the milliseconds with single spaces.

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