PHP獲取時間排除周六、周日的兩個方法
更新時間:2014年06月30日 11:33:44 投稿:junjie
這篇文章主要介紹了PHP獲取時間排除周六、周日的兩個方法,應用在特殊場合,需要的朋友可以參考下
今天和大家分享一個獲取10天后的一個時間戳的函數(shù),程序的關鍵是,他可以不去算周六日哦。如果你有別的需求??梢愿某蒒天的哦。反正就不算周六日。哈哈。
//方法一:
<?php
$now = time(); //指定日期用法 $now = strtotime('2014-01-08') ;
$day = 3600*24;
$total = 12;
$days =array() ;
for ($i=2;$i<$total;$i++)
{
$timer = $now+$day*$i;
$num= date("N",$timer)-2; //周一開始
if($num>=-1 and $num<=3)
{
if(count($days)>=10) break;
$days[]=date("Y-m-d",$now+$day*$i);
$total +=1 ;// $total==12 ?$total+1:$total;
}else
{
$total = $total==12 ?$total+1:$total;
}
}
$i=1;
foreach($days as $day)
{
echo "$i===>".$day."\n";
$i++;
}
//方法二:
function get_days ($date="")
{
$now = empty($date)?time():strtotime($date);
$days = array();
$i = 2;
while(count($days)<10)
{
$timer = $now+3600*24*$i;
$num= date("N",$timer)-2; //周一開始
if($num>=-1 and $num<=3)
{
$days[]=date("Y-m-d",$now+3600*24*$i);
}
$i++;
}
return $days;
}
相關文章
php 提速工具eAccelerator 配置參數(shù)詳解
php 提速工具eAccelerator 配置參數(shù)詳解,需要的朋友可以參考下。2010-05-05
Drupal讀取Excel并導入數(shù)據(jù)庫實例
這篇文章主要介紹了Drupal利用PHPExcel讀取Excel并導入數(shù)據(jù)庫的例子,需要的朋友可以參考下2014-03-03
PHP flush()與ob_flush()的區(qū)別詳解
本篇文章是對PHP中的flush函數(shù)與ob_flush函數(shù)的區(qū)別進行了詳細的分析介紹,需要的朋友參考下2013-06-06
深入mysql_fetch_row()與mysql_fetch_array()的區(qū)別詳解
本篇文章是對mysql_fetch_row()與mysql_fetch_array()的區(qū)別進行了詳細的分析介紹,需要的朋友參考下2013-06-06

