从PHP的时间戳获取时间和日期 [英] Getting time and date from timestamp with php

查看:98
本文介绍了从PHP的时间戳获取时间和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中我有一个时间戳列...这反映了一个这样的格式:2012-04-02 02:57:54

in my database I have a time stamp column...which reflects a format like this: 2012-04-02 02:57:54

不过我会喜欢将它们分成 $ date $ time

However I would like to separate them up into $date and $time.

经过一些研究通过php手册...我发现date(),date_format()和strtotime()能够帮助我分离他们...(不知道如果我是对的)

after some research through the php manual...I found that date() , date_format() and strtotime() are able to help me to separate them...(not sure if I am right)

但我不太清楚如何编码...

but I not very sure of how to code it out...

在我的php文件中提取时间戳将是$ row ['DATETIMEAPP']。

In my php file...the timestamp extracted would be $row['DATETIMEAPP'].

$date= strtotime('d-m-Y',$row['DATETIMEAPP']);
$time= strtotime('Gi.s',$row['DATETIMEAPP']);

$date= date('d-m-Y',$row['DATETIMEAPP']);

工作?

()获得时间?

提前感谢

推荐答案

$timestamp = strtotime($row['DATETIMEAPP']);

给你时间戳,然后你可以使用日期来格式化:

gives you timestamp, which then you can use date to format:

$date = date('d-m-Y', $timestamp);
$time = date('Gi.s', $timestamp);

另外

list($date, $time) = explode('|', date('d-m-Y|Gi.s', $timestamp));

这篇关于从PHP的时间戳获取时间和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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