php 如何将 Unix 时间戳转换回时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5547953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I convert a Unix timestamp back to time?
提问by esafwan
I have the following Unix timestamps.
我有以下 Unix 时间戳。
1301982430 1301982430 1301981474
1301981466 1301981466 1301981066
1301981058 1301981058 1301980388
1301980373 1301980373 1301979082
1301978478 1301978478 1301978478
1301982430 1301982430 1301981474
1301981466 1301981466 1301981066
1301981058 1301981058 1301980388
1301980373 1301980373 1301979082
1301978478 1301978478 1301978478
How do I convert it back to time that's human friendly?
我如何将其转换回人类友好的时间?
This doesn't seem to work,
这似乎不起作用,
strtotime($item->timestamp);
回答by Shakti Singh
You can use the php date function to get the date and time.
您可以使用php date 函数来获取日期和时间。
echo date('Y-m-d h:i:s',$item->timestamp);
回答by ThiefMaster
回答by Luca Fagioli
Use the datefunction.
使用日期函数。
date($format, $timestamp)
As stated:
就像声明的那样:
Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time().
返回根据给定格式字符串格式化的字符串,使用给定的整数时间戳或当前时间(如果没有给定时间戳)。换句话说,timestamp 是可选的,默认为 time() 的值。
Some format examples:
一些格式示例:
$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
回答by Shankar Damodaran
回答by kahriman
echo date('Y-m-d H:i:s',$item->timestamp);
Is perhaps better, because the hour has to be capital!
也许更好,因为时间必须是资本!