当前位置:首页>开发>正文

php时间处理函数你知道多少 请问——php里日期时间,只显示日期的函数是哪个

2023-06-01 11:50:16 互联网 未知 开发

 php时间处理函数你知道多少 请问——php里日期时间,只显示日期的函数是哪个

php时间处理函数你知道多少

使用date函数语法:string date ( string $format [, int $timestamp ] ) 返回将整数 timestamp 按照给定的格式字串而产生的字符串。如果没有给出时间戳则使用本地当前时间。换句话说,timestamp 是可选的,默认值为 time()。 H 小时,24 小时格式,有前导零 00 到 23 echo date("H")

请问——php里日期时间,只显示日期的函数是哪个

$str = 2009-03-30 11:10:05
$timestamp = strtotime($str)
date(Y-m-d, $timestamp)

简单写就是这样:
date(Y-m-d, strtotime(2009-03-30 11:10:05))
输出是:2009-03-30

(注意格式里的"Y-m-d"的大小写。)

php 时间函数

echo date(Y-m-d)
echo "
"
$t = mktime(0,0,0,date("m"),date("d")-1,date("Y"))
echo date(Y-m-d,$t)
echo "
"
$t = mktime(0,0,0,date("m"),date("d")-2,date("Y"))
echo date(Y-m-d,$t)
echo "
"
$t = mktime(0,0,0,date("m"),date("d")-3,date("Y"))
echo date(Y-m-d,$t)
echo "
"
$t = mktime(0,0,0,date("m"),date("d")-4,date("Y"))
echo date(Y-m-d,$t)
echo "
"
$t = mktime(0,0,0,date("m"),date("d")-5,date("Y"))
echo date(Y-m-d,$t)

?>

最新文章

随便看看