色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php checkdate、getdate等日期時間函數(shù)操作詳解

checkdate($month,$date,$year)
  如果應(yīng)用的值構(gòu)成一個有效日期,則該函數(shù)返回為真。例如,對于錯誤日期2005年2月31日,此函數(shù)返回為假。
  在日期用于計算或保存在數(shù)據(jù)庫中之前,可用此函數(shù)檢查日期并使日期生效。
復(fù)制代碼 代碼如下:
<?php
// returns false
echo checkdate(2,30,2005) ? "valid" : "invalid";
// returns true
echo checkdate(4,6,2010) ? "valid" : "invalid";
?>

  getdate($ts)
  在沒有自變量的情況下,該函數(shù)以結(jié)合數(shù)組的方式返回當(dāng)前日期與時間。數(shù)組中的每個元素代表日期/時間值中的一個特定組成部分。可向函數(shù)提交可選的時間標(biāo)簽自變量,以獲得與時間標(biāo)簽對應(yīng)的日期/時間值。
  應(yīng)用此函數(shù)來獲得一系列離散的,容易分離的日期/時間值。
復(fù)制代碼 代碼如下:
<?php
// get date as associative array
$arr = getdate();
echo "Date is " . $arr['mday'] . " " . $arr['weekday'] . " " . $arr['year'];
echo "Time is " . $arr['hours'] . ":" . $arr['minutes'];
?>

  mktime($hour, $minute, $second, $month, $day, $year)
  此函數(shù)的作用與getdate()的作用相反:它由一系列的日期與時間值生成一個UNIX時間標(biāo)簽(GMT時間1970年1月1日到現(xiàn)在消逝的秒數(shù))。不用自變量時,它生成當(dāng)前時間的UNIX時間標(biāo)簽。
  用此函數(shù)獲得即時時間的UNIX時間標(biāo)簽。這種時間標(biāo)簽通常用于許多數(shù)據(jù)庫與程序語言中。
復(fù)制代碼 代碼如下:<?php
// returns timestamp for 13:15:23 7-Jun-2006
echo mktime(13,15,23,6,7,2006);
?>

  date($format, $ts)
  此函數(shù)將UNIX時間標(biāo)簽格式化成一個可人為閱讀的日期字符串。它是php日期/時間API中功能最為強大的函數(shù),可用在一系列的修正值中,將整數(shù)時間標(biāo)簽轉(zhuǎn)變?yōu)樗璧淖址袷健?
  為顯示格式化時間或日期時,應(yīng)用此函數(shù)。
復(fù)制代碼 代碼如下:
<?php
// format current date
// returns "13-Sep-2005 01:16 PM"
echo date("d-M-Y h:i A", mktime());
?>

  strtotime($str)
  此函數(shù)將可人為閱讀的英文日期/時間字符串轉(zhuǎn)換成UNIX時間標(biāo)簽。
  應(yīng)用此函數(shù)將非標(biāo)準(zhǔn)化的日期/時間字符串轉(zhuǎn)換成標(biāo)準(zhǔn)、兼容的UNIX時間標(biāo)簽。
復(fù)制代碼 代碼如下:
<?php
// returns 13-Sep-05
echo date("d-M-y", strtotime("today"));
// returns 14-Sep-05
echo date("d-M-y", strtotime("tomorrow"));
// returns 16-Sep-05
echo date("d-M-y", strtotime("today +3 days"));
?>

  strftime($format,$ts)
  如前面的setlocale()函數(shù)定義的那樣,此函數(shù)將UNIX時間標(biāo)簽格式化成適用于當(dāng)前環(huán)境的日期字符串。
  應(yīng)用此函數(shù)建立與當(dāng)前環(huán)境兼容的日期字符串。
復(fù)制代碼 代碼如下:
<?php
// set locale to France (on Windows)
setlocale(LC_TIME, "fra_fra");
// format month/day names
// as per locale setting
// returns "septembre" and "mardi"
echo strftime("Month: %B ");
echo strftime("Day: %A ");
?>

microtime()
  如前面的setlocale()函數(shù)定義的那樣,此函數(shù)將UNIX時間標(biāo)簽格式化成適用于當(dāng)前環(huán)境的日期字符串。
  應(yīng)用此函數(shù)建立與當(dāng)前環(huán)境兼容的日期字符串。
復(fù)制代碼 代碼如下:
<?php
// get starting value
$start = microtime();
// run some code
for ($x=0; $x<1000; $x++) {
$null = $x * $x;
}
// get ending value
$end = microtime();
// calculate time taken for code execution
echo "Elapsed time: " . ($end - $start) ." sec";
?>

  gmmktime($hour, $minute, $second, $month, $day, $year)
  此函數(shù)由一系列用GMT時間表示的日期與時間值生成一個UNIX時間標(biāo)簽。不用自變量時,它生成一個當(dāng)前GMT即時時間的UNIX時間標(biāo)簽。
  用此函數(shù)來獲得GMT即時時間的UNIX時間標(biāo)簽。
復(fù)制代碼 代碼如下:
<?php
// returns timestamp for 12:25:23 9-Jul-2006
echo gmmktime(12,25,23,7,9,2006);
?>

  gmdate($format, $ts)
  此函數(shù)將UNIX時間標(biāo)簽格式化成可人為閱讀的日期字符串。此日期字符串以GMT(非當(dāng)?shù)貢r間)表示。
  用GMT表示時間標(biāo)簽時應(yīng)用此函數(shù)。
復(fù)制代碼 代碼如下:
<?php
// format current date into GMT
// returns "13-Sep-2005 08:32 AM"
echo gmdate("d-M-Y h:i A", mktime());
?>

  date_default_timezone_set($tz)、date_default_timezone_get()
  此函數(shù)此后所有的日期/時間函數(shù)調(diào)用設(shè)定并恢復(fù)默認的時區(qū)。
  注:此函數(shù)僅在php 5.1+中有效。
  此函數(shù)是一個方便的捷徑,可為以后的時間操作設(shè)定時區(qū)。
復(fù)制代碼 代碼如下:
<?php
// set timezone to UTC
date_default_timezone_set('UTC');
?>

php技術(shù)php checkdate、getdate等日期時間函數(shù)操作詳解,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 宿松县| 武邑县| 晋城| 福海县| 富裕县| 涟源市| 隆尧县| 新建县| 盐津县| 浪卡子县| 象山县| 河池市| 周口市| 鄂州市| 普兰县| 庆安县| 安义县| 沙洋县| 宁陵县| 渑池县| 虎林市| 安义县| 平顶山市| 灵川县| 南昌市| 清新县| 双桥区| 武冈市| 巧家县| 会同县| 平昌县| 兴义市| 斗六市| 栖霞市| 南郑县| 遂川县| 娱乐| 尼勒克县| 宽甸| 太康县| 改则县|