datetphp
A. php怎么样把时间戳换成日期
php把时间戳换成日期,用到的工具,notepad++,步骤如下:
php代码部分:
<?php
$t=time();
echo"今天的日期时间戳是:".$t."<br/>";
echo"把时间戳转换成日期:".date("Y-m-dH:i:s",$t);
?>
说明:先获取当前日期的时间戳,然后通过data函数将时间戳转换成日期,$t可以是任意的时间戳。
运行以后的效果图:
注意事项:代码必须在php环境下运行。
B. php获取当前时间
PHP获取当前时间可以使用time函数,函数格式为 int time ( void ),返回自从 Unix 纪元(格林威治时间 1970 年 1 月 1 日 00:00:00)到当前时间的秒数。
把time格式的时间以年月日时分秒的格式输出,可以使用date函数,格式是string date ( string $format [, int $timestamp ] ),例子代码:
<?php
$t=time();
echo"$t ";
echodate('Y-m-dH:i:s',$t)
?>
运行结果为:
E:TEMP文件exp>a.php
1451271607
2015-12-2811:00:07
date函数的格式化字符许多,主要的有下面这些:
年:
L 是否为闰年 如果是闰年为 1,否则为 0
o ISO-8601 格式年份数字。这和 Y 的值相同,只除了如果 ISO 的星期数(W)属于前一年或下一年,则用那一年。(PHP 5.1.0 新加) Examples: 1999 or 2003
Y 4 位数字完整表示的年份 例如:1999 或 2003
y 2 位数字表示的年份 例如:99 或 03
月:
F 月份,完整的文本格式,例如 January 或者 March January 到 December
m 数字表示的月份,有前导零 01 到 12
M 三个字母缩写表示的月份 Jan 到 Dec
n 数字表示的月份,没有前导零 1 到 12
t 给定月份所应有的天数 28 到 31
日:
d 月份中的第几天,有前导零的 2 位数字 01 到 31
D 星期中的第几天,文本表示,3 个字母 Mon 到 Sun
j 月份中的第几天,没有前导零 1 到 31
l(“L”的小写字母) 星期几,完整的文本格式 Sunday 到 Saturday
N ISO-8601 格式数字表示的星期中的第几天(PHP 5.1.0 新加) 1(表示星期一)到 7(表示星期天)
S 每月天数后面的英文后缀,2 个字符 st,nd,rd或者 th。可以和 j 一起用
w 星期中的第几天,数字表示 0(表示星期天)到 6(表示星期六)
z 年份中的第几天 0 到 366
星期:
W ISO-8601 格式年份中的第几周,每周从星期一开始(PHP 4.1.0 新加的) 例如:42(当年的第 42 周)
时间:
a 小写的上午和下午值 am 或 pm
A 大写的上午和下午值 AM 或 PM
B Swatch Internet 标准时 000 到 999
g 小时,12 小时格式,没有前导零 1 到 12
G 小时,24 小时格式,没有前导零 0 到 23
h 小时,12 小时格式,有前导零 01 到 12
H 小时,24 小时格式,有前导零 00 到 23
i 有前导零的分钟数 00 到 59>
s 秒数,有前导零 00 到 59>
C. php 如何用date取得指定月份有多少天
$time = strtotime("2013-02-01");
echo date('t', $time);
你思路是对的,只要把日期格式补完就可以了。
D. PHP DATE 如何取得当月的第一天和最后一天
<?php
$first_day=date('Y-m-01');//第一天,肯定是1号了,这是送分的
$last_day=date('Y-m-t');//最后一天,t表示每月有多少天,也相当于送分的……
echo"第一天:{$first_day}最后一天:{$last_day}";
E. php的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"
F. php如何输出date日期
可以借助php函数date()输出日期。
date()函数:格式化一个本地时间/日期。
说明:
stringdate(string$format[,int$timestamp])
返回将整数 timestamp
按照给定的格式字串而产生的字符串。如果没有给出时间戳则使用本地当前时间。换句话说,timestamp
是可选的,默认值为 time()。
范例:
<?php
//假定今天是:March10th,2001,5:16:18pm
$today=date("Fj,Y,g:ia");//March10,2001,5:16pm
$today=date("m.d.y");//03.10.01
$today=date("j,n,Y");//10,3,2001
$today=date("Ymd");//20010310
$today=date('h-i-s,j-m-y,itiswDayz');//05-16-17,10-03-01,163116186Fripm01
$today=date('i is hejSday.');//Itisthe10thday.
$today=date("DMjG:i:sTY");//SatMar1015:16:08MST2001
$today=date('H:m:smis\mo h');//17:03:17mismonth
$today=date("H:i:s");//17:16:17
$today=date("Y-m-dH:i:s");//2001-03-1017:16:18(MySQLDATETIME格式)
?>
G. 如何用PHP制作日历
calendar.class.php
代码如下:
<?php
classCalendar{
private$year;//当前的年
private$month;//当前的月
private$start_weekday;//当月的第一天对应的是周几
private$days;//当前月一共多少天
function__construct(){
$this->year=isset($_GET["year"])?$_GET["year"]:date("Y");
$this->month=isset($_GET["month"])?$_GET["month"]:date("m");
$this->start_weekday=date("w",mktime(0,0,0,$this->month,1,$this->year));
$this->days=date("t",mktime(0,0,0,$this->month,1,$this->year));
}
functionout(){
echo'<tablealign="center">';
$this->chageDate("test.php");
$this->weeksList();
$this->daysList();
echo'</table>';
}
privatefunctionweeksList(){
$week=array('日','一','二','三','四','五','六');
echo'<tr>';
for($i=0;$i<count($week);$i++)
echo'<thclass="fontb">'.$week[$i].'</th>';
echo'</tr>';
}
privatefunctiondaysList(){
echo'<tr>';
//输出空格(当前一月第一天前面要空出来)
for($j=0;$j<$this->start_weekday;$j++)
echo'<td></td>';
for($k=1;$k<=$this->days;$k++){
$j++;
if($k==date('d'))
echo'<tdclass="fontb">'.$k.'</td>';
else
echo'<td>'.$k.'</td>';
if($j%7==0)
echo'</tr><tr>';
}
//后面几个空格
while($j%7!==0){
echo'<td></td>';
$j++;
}
echo'</tr>';
}
privatefunctionprevYear($year,$month){
$year=$year-1;
if($year<1970)
$year=1970;
return"year={$year}&month={$month}";
}
privatefunctionprevMonth($year,$month){
if($month==1){
$year=$year-1;
if($year<1970)
$year=1970;
$month=12;
}else{
$month--;
}
return"year={$year}&month={$month}";
}
privatefunctionnextYear($year,$month){
$year=$year+1;
if($year>2038)
$year=2038;
return"year={$year}&month={$month}";
}
privatefunctionnextMonth($year,$month){
if($month==12){
$year++;
if($year>2100)
$year=2100;
$month=1;
}else{
$month++;
}
return"year={$year}&month={$month}";
}
privatefunctionchageDate($url=""){
echo'<tr>';
echo'<td><ahref="?'.$this->prevYear($this->year,$this->month).'">'.'<<'.'</a></td>';
echo'<td><ahref="?'.$this->prevMonth($this->year,$this->month).'">'.'<'.'</a></td>';
echo'<tdcolspan="3">';
echo'<form>';
echo'<selectname="year"onchange="window.location=''.$url.'?year='+this.options[selectedIndex].value+'&month='.$this->month.''">';
for($sy=1970;$sy<=2100;$sy++){
$selected=($sy==$this->year)?"selected":"";
echo'<option'.$selected.'value="'.$sy.'">'.$sy.'</option>';
}
echo'</select>';
echo'<selectname="month"onchange="window.location=''.$url.'?year='.$this->year.'&month='+this.options[selectedIndex].value">';
for($sm=1;$sm<=12;$sm++){
$selected1=($sm==$this->month)?"selected":"";
echo'<option'.$selected1.'value="'.$sm.'">'.$sm.'</option>';
}
echo'</select>';
echo'</form>';
echo'</td>';
echo'<td><ahref="?'.$this->nextYear($this->year,$this->month).'">'.'>>'.'</a></td>';
echo'<td><ahref="?'.$this->nextMonth($this->year,$this->month).'">'.'>'.'</a></td>';
echo'</tr>';
}
}
?>test.php
代码如下:
<style>
table{
border:1pxsolid#050;
}
.fontb{
color:white;
background:blue;
}
th{
width:30px;
}
td,th{
height:30px;
text-align:center;
}
form{
margin:0px;
padding:0px;
}
</style>
<?php
include"calendar.class.php";
$calendar=newCalendar;
$calendar->out();
?>
H. php date函数
¥T变量是时间戳吗