如何使用php从时间戳中修剪时间 [英] How to trim the time from the timestamp using php
本文介绍了如何使用php从时间戳中修剪时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的表中使用了时间戳.2012-07-30 10:12:39 是我的mysql记录中的时间格式.如何修剪时间并只显示日期.在 php 页面中?
I used timestamp to my table . 2012-07-30 10:12:39 is the format of time in my mysql records.How to to trim the time and display only date. in php page ?
推荐答案
$mysqlDateTime = "2012-07-30 10:12:39";
如果你只需要日期,你可以使用这样的(简单的):
If you just need the date from that, you can use something like this (easy) one:
list($date, $time) = explode(" ", $mysqlDateTime);
echo $date;
但是,您也可以使用以下内容:
However, you may use also something like this:
echo date("Y-m-d", strtotime($mysqlDateTime));
编辑
donald123 的解决方案可能对您也很有趣.
The solution of donald123 may also be interesting for you.
这篇关于如何使用php从时间戳中修剪时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文