Getting time and date from timestamp with php(使用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']);
工作?
我也可以使用 date() 来获取时间吗??
Can i use date() to get the time as well??
提前致谢
推荐答案
$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从时间戳获取时间和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用php从时间戳获取时间和日期
基础教程推荐
- php中的PDF导出 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Web 服务器如何处理请求? 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
