1、時間戳:表示從計算機元年/unix紀年(0時區 1970/1/1 00:00:00)到當前事件的秒數。是乙個長整形的數字。
2、取到時間戳的函式:
① time():返回當前時間的時間戳;
② mktime():根據設定的時間,返回時間戳。
設定的格式:時,分,秒,月,日,年
③ strtotime():將輸入的字串日期轉為時間戳;
eg:echo strtotime("2017-06-02 09:42:00");
echo strtotime("july 1st, 2008 09:42:00");
echo strtotime("now");
echo strtotime("+1 day");
3、時間戳的格式化:
① 使用getdate()函式:(並不常用);
返回乙個陣列,陣列的鍵值如下
'seconds' => int 47 秒
'minutes' => int 56 分
'hours' => int 9 小時
'mday' => int 2 乙個月的第幾天
'wday' => int 5 乙個周的第幾天
'mon' => int 6 陣列的幾月
'year' => int 2017 年份
'yday' => int 152 一年中的第幾天
'weekday' => string 'friday' (length=6) 字串的英文週幾
'month' => string 'june' (length=4) 字串的英文月份
0 => int 1496368607 原始的時間戳
② 使用date()函式:非常常用
string date(string "格式化字串"[,int 時間戳 = time()]);
格式化的字串:
y:四位數年 m:月01-12 n:月1-12 d:天01-31 j:天1-31
h:時24時制 h:小時12制 i:分鐘00-59 s:秒00-59 w:星期幾0-6
a:上午am或下午pm a:上午am或下午pm。
4、時區設定:
① 修改php.ini配置檔案:
date.timezone = etc/gmt-8
② 使用date_default_timezone_set();函式
date_default_timezone_set("etc/gmt-8");//直接指定時區,西加東減
date_default_timezone_set("prc");//中華人民共和國
date_default_timezone_set("asia/shanghai");//亞洲上海
取到當前時區設定:date_default_timezone_get();
5、了解microtime(true);取到從計算機元年到現在的微秒數;
預設顯示為0.78026400 1496372572 單位為秒,前面是小數點後部分,後面為小數
下面我們就開始寫**嘍!
date_default_timezone_set("prc");
//取到 年 月 日
$time = getdate();
$mday = $time["mday"];
$mon = $time["mon"];
$year = $time["year"];
//判斷一下一年中各個月份有幾天的情況
if($mon==4||$mon==6||$mon==9||$mon==11)elseif($mon==2)else
}else
//取到這個月的1號是第幾天,
$w = getdate(mktime(0,0,0,$mon,1,$year))["wday"];
//製作日曆的大框架。用for遍歷陣列,列印出乙個日曆的格式。
$date = function($day,$w)
if($w>=1&&$w<=6)
}$n=0;
for($j=1;$j<=count($arr);$j++)else
if($n==7)
}if($n!=7)echo "";
echo "";
};$date($day,$w);
這是效果圖。
乙個日曆程式
year currentdate 年 month currentdate 月 hiddenid getusername 3 日一 二三四五 六 ym year currentdate month currentdate i 1do while i 33 j 1response.write do wh...
乙個日曆C程式
由於c語言當初沒學好,像c的結構體,檔案流,指標等都還弄不明白。下面是最近的乙個 關於列印日曆的。calendar 列印出某年的日曆,由使用者指出1月1日是星期幾以及該年是否為閏年。表示1月1日是星期幾的編碼 0 sunday 1 monday 2 tuesday 3 wednesday 4 thu...
乙個日曆小程式
include define sunday 0 define monday 1 define tuesday 2 define wednesday 3 define thursday 4 define friday 5 define saturday 6 void giveinstructions ...