time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒
要找出前一天的时间就是 time()-60*60*24;
要找出前一年的时间就是 time()*60*60*24*365
那么如何把这个数字换成日期格式呢,就要用到date函数了
$t=time();
echo date("Y-m-d H:i:s",$t);
第一个参数的格式分别表示:
a - "am" 或是 "pm"
A - "AM" 或是 "PM"
d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"
D - 星期几,三个英文字母; 如: "Fri"
F - 月份,英文全名; 如: "January"
h - 12 小时制的小时; 如: "01" 至 "12"
H - 24 小时制的小时; 如: "00" 至 "23"
g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"
G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"
i - 分钟; 如: "00" 至 "59"
j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"
l - 星期几,英文全名; 如: "Friday"
m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"
n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"
M - 月份,三个英文字母; 如: "Jan"
s - 秒; 如: "00" 至 "59"
S - 字尾加英文序数,二个英文字母; 如: "th","nd"
t - 指定月份的天数; 如: "28" 至 "31"
U - 总秒数
w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)
Y - 年,四位数字; 如: "1999"
y - 年,二位数字; 如: "99"
z - 一年中的第几天; 如: "0" 至 "365"
其它不在上列的字符则直接列出该字符
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
$month=date("n");
$today=date("j");
if($today>=1 and $today<=10)
{
echo "今天是".$month."月".$today."日"."上旬";}
elseif($today>10 and $today<=20){
echo "今天是".$month."月".$today."日"."中旬";}
else
{echo "今天是".$month."月".$today."日"."下旬";}
echo "<br>";
echo "<br>";
echo "<br>";
echo date("Y.m.d");
?>
</body>
</html>