最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php中strtotime函數(shù)用法詳解

 更新時間:2014年11月15日 14:44:25   投稿:shichen2014  
這篇文章主要介紹了php中strtotime函數(shù)的用法,以實(shí)例形式詳細(xì)分析了strtotime函數(shù)的參數(shù)含義與相應(yīng)的用法,適用于時間格式變換的情況,需要的朋友可以參考下

本文實(shí)例講述了php中strtotime函數(shù)用法。分享給大家供大家參考。具體如下:

strtotime(字符串$時間[,詮釋$現(xiàn)在])int strtotime(string $time [,int $now] 該函數(shù)期望得到一個包含美國英語日期格式,并會嘗試解析成一個Unix時間戳(多少秒自1970年1月1日00:00:00星期一該格式),相對于現(xiàn)在提供的時間戳,或當(dāng)前時間如果現(xiàn)在不提供

這個函數(shù)將使用TZ環(huán)境變量(如果有)來計(jì)算時間戳,自PHP 5.1.0有更容易的方法來確定所使用的所有/日期時間函數(shù)的時區(qū),這一過程是解釋在date_default_timezone_get()函數(shù)的一頁.

解析的字符串,在PHP 5.0.0,不允許在微秒的時間,自PHP 5.0.0他們是允許的,但忽略.

現(xiàn)在哪些是作為計(jì)算基數(shù)相對日期使用時間戳.

返回值:在成功返回一個時間戳,否則返回FALSE,前到PHP 5.1.0,這個函數(shù)將返回失敗-1.

現(xiàn)在我們來看看strtotime字符轉(zhuǎn)換成時間的函數(shù)實(shí)例,代碼如下:

復(fù)制代碼 代碼如下:
<?php
//function
function nextWeeksDay($date_begin,$nbrweek)
{
$nextweek=array();
for($i = 1; $i <= $nbrweek; $i++)  { // 52 week in one year of coursewww.phpfensi.com
$nextweek[$i]=date('D d M Y', strtotime('+'.$i.' week',$date_begin));
}
return $nextweek;
}
/// end function 
/// example of a select date 
// var
$date_begin = strtotime('06-05-2010'); //D Day Month Year  - like function format.
$nbrweek=52;
// call function
$result=nextWeeksDay($date_begin,$nbrweek);
// Preview 
for($i = 1; $i <= $nbrweek; $i++)  {
echo '<br> - '.$result[$i];
}
?>
 
<?php
$str = 'Not Good';
 
// previous to PHP 5.1.0 you would compare with -1, instead of false
if (($timestamp = strtotime($str)) === false) {
    echo "The string ($str) is bogus";
} else {
    echo "$str == " . date('l dS o F Y h:i:s A', $timestamp);
}
?> 
<?php
echo strtotime("now"), " ";
echo strtotime("10 September 2000"), " ";
echo strtotime("+1 day"), " ";
echo strtotime("+1 week"), " ";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), " ";
echo strtotime("next Thursday"), " ";
echo strtotime("last Monday"), " ";
?>

這是一個快速函數(shù)計(jì)算在一年期間,“工作天”,“工作日”是指那些沒有周末,沒有假期在$數(shù)組中指定的假日,實(shí)例代碼如下:
復(fù)制代碼 代碼如下:
function get_working_days($to_date) {
    $holidays = array(
        1 => array(10), //2011 ...
        2 => array(11),
        3 => array(21), //... 2011
        4 => array(29,30), //2010 ...
        5 => array(3,4,5),
        6 => array(),
        7 => array(19),
        8 => array(11,12,13),
        9 => array(20,23),
       10 => array(11),
       11 => array(3,23),
       12 => array(23) //... 2010
    );
 
    for($to_date, $w = 0, $i = 0, $x = time(); $x < $to_date; $i++, $x = strtotime("+$i day")) {
       if(date("N",$x) < 6 &! in_array(date("j",$x),$holidays[date("n",$x)])) $w++;
    }
    return $w;
}
 
//Usage:
echo get_working_days(strtotime("2011-01-08"));

希望本文所述對大家的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論

股票| 苏尼特右旗| 色达县| 普格县| 海南省| 乡宁县| 法库县| 方正县| 佛山市| 沙雅县| 尚义县| 沧州市| 竹山县| 彭州市| 麦盖提县| 额尔古纳市| 正镶白旗| 南京市| 饶河县| 九台市| 普安县| 望城县| 万源市| 临泉县| 安岳县| 革吉县| 岐山县| 耒阳市| 页游| 从江县| 龙江县| 鸡西市| 三亚市| 贵溪市| 定西市| 遂川县| 理塘县| 卢龙县| 金乡县| 根河市| 莱西市|