esa*_*wan 14 php time unix-timestamp
我有以下Unix时间戳.
1301982430 1301982430 1301981474
1301981466 1301981466 1301981066
1301981058 1301981058 1301980388
1301980373 1301980373 1301979082
1301978478 1301978478 1301978478
如何将其转换回人性化的时间?
这似乎不起作用,
strtotime($item->timestamp);
Run Code Online (Sandbox Code Playgroud)
Sha*_*ngh 36
您可以使用php日期函数来获取日期和时间.
echo date('Y-m-d h:i:s',$item->timestamp);
Run Code Online (Sandbox Code Playgroud)
echo strftime("%Y-%m-%d, %H:%M:%S", time());
echo date('Y-m-d, H:i:s');
Run Code Online (Sandbox Code Playgroud)
使用日期功能.
date($format, $timestamp)
Run Code Online (Sandbox Code Playgroud)
就像声明的那样:
使用给定的整数时间戳返回根据给定格式字符串格式化的字符串,如果没有给出时间戳,则返回当前时间.换句话说,timestamp是可选的,默认为time()的值.
一些格式示例:
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
Run Code Online (Sandbox Code Playgroud)