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

首頁 > 語言 > PHP > 正文

php strtotime()函數時間日期轉換

2024-09-04 11:45:36
字體:
來源:轉載
供稿:網友

在php中strtotime() 函數將任何英文文本的日期時間描述解析為 Unix 時間戳,這個函數也是我們經常會用到的,有需要的朋友參考一下.

語法:strtotime(time,now)

參數 描述 

time 規定要解析的時間字符串.

now 用來計算返回值的時間戳,如果省略該參數,則使用當前時間.

例子,代碼如下:

  1. <?php 
  2. echo(strtotime("now")); 
  3. echo(strtotime("3 October 2005")); 
  4. echo(strtotime("+5 hours")); 
  5. echo(strtotime("+1 week")); 
  6. echo(strtotime("+1 week 3 days 7 hours 5 seconds")); 
  7. echo(strtotime("next Monday")); 
  8. echo(strtotime("last Sunday")); 
  9. ?> 
  10. //輸出: 
  11. 1138614504 
  12. 1128290400 
  13. 1138632504 
  14. 1139219304 
  15. 1139503709 
  16. 1139180400 
  17. 1138489200 

Example #1 strtotime() 例子,代碼如下:

  1. <?php 
  2. echo strtotime("now"), "n"
  3. echo strtotime("10 September 2000"), "n"
  4. echo strtotime("+1 day"), "n"
  5. echo strtotime("+1 week"), "n"
  6. echo strtotime("+1 week 2 days 4 hours 2 seconds"), "n"
  7. echo strtotime("next Thursday"), "n"
  8. echo strtotime("last Monday"), "n"
  9. ?>   

Example #2 失敗檢查,代碼如下:

  1. <?php 
  2. $str = 'Not Good'
  3.  
  4. // previous to PHP 5.1.0 you would compare with -1, instead of false 
  5. if (($timestamp = strtotime($str)) === false) { 
  6.     echo "The string ($str) is bogus"
  7. else { 
  8.     echo "$str == " . date('l dS of F Y h:i:s A'$timestamp); 
  9. ?> 
  10.  
  11. I just found out PHP thinks slashes in date-formats aren't very european: 
  12. (I guess this is not a bug, just the way it works. But correct me if I'm wrong.) 
  13. <?php 
  14.  
  15.     $date = "06/10/2011 14:28"// 6 october 2011 2:28 pm 
  16.     $otherDate = "06-10-2011 14:28"// 6 october 2011 2:28 pm 
  17.      
  18.     echo $stamp = strtotime($date) . "<br />"// outputs 1307708880 
  19.     echo $otherStamp = strtotime($otherDate) . "<br />"// outputs 1317904080//開源代碼Vevb.com 
  20.      
  21.     echo date("d-m"$stamp); // outputs 10-06 
  22.     echo date("d-m"$otherStamp); // outputs 06-10 
  23.  
  24. ?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贺兰县| 怀安县| 赣州市| 泸溪县| 洪泽县| 乌拉特后旗| 建阳市| 永顺县| 南华县| 姜堰市| 西乌珠穆沁旗| 太谷县| 和平县| 蒙阴县| 奉节县| 乐清市| 汉中市| 宜宾市| 新兴县| 滨州市| 连江县| 平乡县| 呈贡县| 攀枝花市| 始兴县| 敖汉旗| 夏津县| 棋牌| 通化县| 满洲里市| 巴林左旗| 开江县| 黄梅县| 保亭| 黄浦区| 霍城县| 富蕴县| 镇安县| 泽州县| 固原市| 嘉定区|