<?php
header("Content-type:text/html; charset=utf-8");
/* date() : 向浏览器输出标准时间
*/
echo 'Today is '.date("F d,Y").'<br>';
// output:Today is November 25,2017
//输出星期几
echo date("l").'<br>'; // output Saturday
echo date("m-d-Y").'<br>'; // output:11-25-2017
echo date("h:i:sa").'<br>'; // output:08:38:36
/* gettimeofday() 了解当前时间的更多信息 , 返回与当前时间有关的元素所组成的一个关联数组
* dsttime:日光节约时间算法 minuteswest:格林尼治标准时间(GMT),西部的分钟数 sec usec
*/
$time = gettimeofday();
$UTCoffset = $time['minuteswest']/60;
printf("server location is %d hours west of UTC<br>",$UTCoffset);
/* 时间戳
* time() 返回时间戳,mktime() 根据特定日期创建时间戳
*/
echo time().'<br>'; // output:1511639270 时间戳
echo date('F d,Y h:i:s',time())."<br>"; //November 25,2017 08:47:50
$now = time();
$taxday = mktime(0,0,0,4,15,2010);
$difference = $taxday - $now; //diffenence in seconds
$hours = round($difference / 60 / 60);
echo "Only $hours hours until tax day!".'<br>';
/* getlastmod() 显示网页最新修改时间
*/
$lastmod = date('F d, Y h:i:sa', getlastmod());
echo "Page last modified on $lastmod".'<br>';
$date = new Datetime();
echo $date->format("Y-m-d h:i:sa").'<br>'; //格式化日期
$date = new Datetime("21:55"); //设置时间
echo $date->format("Y-m-d h:i:sa").'<br>'; //格式化日期