Php将Mac Unix时间戳转换为Y-m-d G:i:s[复制]

时间:2021-10-04 21:29:59

This question already has an answer here:

这个问题已经有了答案:

I am trying to convert a Mac UNIX timestamp to date time.

我正在尝试将Mac UNIX时间戳转换为日期时间。

3448286095 should be converted to 2013-04-09 00:14:55.

3448286095应改为2013-04-09 00:14:55。

I tried:

我试着:

echo date('Y-m-d G:i:s', strtotime(3448286095));

回声日期(Y-m-d G:我:年代”,strtotime(3448286095);

The output is not correct.

输出不正确。

UNIX Timestamp: seconds since Jan 1, 1970.
Mac Timestamp: seconds since Jan 1, 1904.

UNIX时间戳:自1970年1月1日起秒。Mac时间戳:从1904年1月1日开始。

1 个解决方案

#1


1  

Well, another stupid Mac Timestamp-only approach:

另一个愚蠢的Mac时间戳方法:

date_default_timezone_set('UTC');
$date = new DateTime(gmdate('Y-m-d H:i:s', 3448286095));
$date->sub(new DateInterval('P66Y'));
echo $date->format('Y-m-d H:i:s');

which output:

输出:

2013-04-09 17:14:55

#1


1  

Well, another stupid Mac Timestamp-only approach:

另一个愚蠢的Mac时间戳方法:

date_default_timezone_set('UTC');
$date = new DateTime(gmdate('Y-m-d H:i:s', 3448286095));
$date->sub(new DateInterval('P66Y'));
echo $date->format('Y-m-d H:i:s');

which output:

输出:

2013-04-09 17:14:55