使用 PHP 将 Facebook 时间转换为人类可读的时间 [英] Converting facebook time to human readable time with PHP

查看:33
本文介绍了使用 PHP 将 Facebook 时间转换为人类可读的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 facebook 检索了这个时间值:1438306200

I retrieved this time value from facebook: 1438306200

如何使用 PHP 将其转换为人类可读的格式?

How do I convert it to human readable format with PHP?

I tried: date('Y-m-d H:i:s', strtotime( 1438306200  ));

但它返回:1970-01-01 01:00:00

But it returns: 1970-01-01 01:00:00

我是新来的.非常感谢您的帮助!:)

I'm kinda new here. many thanks for any help! :)

推荐答案

不需要 strtotime( ) 调用,它已经是一个时间戳:

There's no need for the strtotime( ) call, it's already a timestamp:

<?php
echo date( 'Y-m-d H:i:s', '1438306200' );
// output = '2015-07-31 03:30:00'.

编辑:您收到的另一个日期 (1970-1-1) 是 Unix Epoch,这是 PHP 能够返回的第一个日期.strtotime( '1438306200' ) 等于 0,因为您传递的是时间戳,而不是字符串.将 0 有效地传递给日期意味着距纪元 0 秒",这会导致返回 1970-1-1.只是让你知道;)

Edit: the other date you received (1970-1-1) is the Unix Epoch, which is the first date PHP is able to return. strtotime( '1438306200' ) equals 0 as what you passed is a time stamp, not a string. Passing 0 to date effectively means "0 seconds from epoch", which results in 1970-1-1 being returned. Just so you know ;)

这篇关于使用 PHP 将 Facebook 时间转换为人类可读的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆