国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

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

2024-09-04 11:43:07
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php中strtotime函數(shù)的用法,以實例形式詳細(xì)分析了strtotime函數(shù)的參數(shù)含義與相應(yīng)的用法,適用于時間格式變換的情況,需要的朋友可以參考下

本文實例講述了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)境變量(如果有)來計算時間戳,自PHP 5.1.0有更容易的方法來確定所使用的所有/日期時間函數(shù)的時區(qū),這一過程是解釋在date_default_timezone_get()函數(shù)的一頁.

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

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

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

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

  1. <?php 
  2. //function 
  3. function nextWeeksDay($date_begin,$nbrweek
  4. $nextweek=array(); 
  5. for($i = 1; $i <= $nbrweek$i++)  { // 52 week in one year of coursewww.survivalescaperooms.com 
  6. $nextweek[$i]=date('D d M Y'strtotime('+'.$i.' week',$date_begin)); 
  7. return $nextweek
  8. /// end function  
  9. /// example of a select date  
  10. // var 
  11. $date_begin = strtotime('06-05-2010'); //D Day Month Year  - like function format. 
  12. $nbrweek=52; 
  13. // call function 
  14. $result=nextWeeksDay($date_begin,$nbrweek); 
  15. // Preview  
  16. for($i = 1; $i <= $nbrweek$i++)  { 
  17. echo '<br> - '.$result[$i]; 
  18. ?> 
  19.  
  20. <?php 
  21. $str = 'Not Good'
  22.  
  23. // previous to PHP 5.1.0 you would compare with -1, instead of false 
  24. if (($timestamp = strtotime($str)) === false) { 
  25.     echo "The string ($str) is bogus"
  26. else { 
  27.     echo "$str == " . date('l dS o F Y h:i:s A'$timestamp); 
  28. //www.survivalescaperooms.com 
  29. ?>  
  30. <?php 
  31. echo strtotime("now"), " "
  32. echo strtotime("10 September 2000"), " "
  33. echo strtotime("+1 day"), " "
  34. echo strtotime("+1 week"), " "
  35. echo strtotime("+1 week 2 days 4 hours 2 seconds"), " "
  36. echo strtotime("next Thursday"), " "
  37. echo strtotime("last Monday"), " "
  38. ?> 

這是一個快速函數(shù)計算在一年期間,“工作天”,“工作日”是指那些沒有周末,沒有假期在$數(shù)組中指定的假日,實例代碼如下:

  1. function get_working_days($to_date) { 
  2.     $holidays = array
  3.         1 => array(10), //2011 ... 
  4.         2 => array(11), 
  5.         3 => array(21), //... 2011 
  6.         4 => array(29,30), //2010 ... 
  7.         5 => array(3,4,5), 
  8.         6 => array(), 
  9.         7 => array(19), 
  10.         8 => array(11,12,13), 
  11.         9 => array(20,23), 
  12.        10 => array(11), 
  13.        11 => array(3,23), 
  14.        12 => array(23) //... 2010 
  15.     ); 
  16.  
  17.     for($to_date$w = 0, $i = 0, $x = time(); $x < $to_date$i++, $x = strtotime("+$i day")) { 
  18.        if(date("N",$x) < 6 &! in_array(date("j",$x),$holidays[date("n",$x)])) $w++; 
  19.     } 
  20.     return $w
  21.  
  22. //Usage: 
  23. echo get_working_days(strtotime("2011-01-08")); 

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 永定县| 镇巴县| 万宁市| 根河市| 宜良县| 科技| 沈阳市| 康马县| 崇明县| 清流县| 巴林右旗| 抚松县| 边坝县| 石嘴山市| 桓仁| 灵石县| 洛浦县| 来凤县| 杂多县| 丹寨县| 浦江县| 灯塔市| 沧州市| 沙湾县| 上饶市| 红河县| 奇台县| 彰化市| 称多县| 营口市| 金塔县| 大方县| 绵竹市| 云浮市| 宁波市| 荥经县| 滁州市| 九江市| 韶山市| 黄梅县| 廉江市|