在我的数据库中,我有一个时间戳列...它反射(reflect)了如下格式:2012-04-02 02:57:54
但是我想将它们分成 $date
和 $time
。
通过php手册进行一些研究...我发现date()
、date_format()
和strtotime()
都可以帮我把它们分开......(不确定我是否正确)
但我不太清楚如何编码...
在我的 php 文件中...提取的时间戳将是 $row['DATETIMEAPP']
。
会
$date = strtotime('d-m-Y',$row['DATETIMEAPP']);
$time = strtotime('Gi.s',$row['DATETIMEAPP']);
或
$date = date('d-m-Y',$row['DATETIMEAPP']);
工作?
我可以使用 date()
来获取时间吗??
提前致谢
最佳答案
$timestamp = strtotime($row['DATETIMEAPP']);
给你时间戳,然后你可以使用日期来格式化:
$date = date('d-m-Y', $timestamp);
$time = date('Gi.s', $timestamp);
或者
list($date, $time) = explode('|', date('d-m-Y|Gi.s', $timestamp));
关于php - 使用php从时间戳获取时间和日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9970584/