今天和大家分享一个获取10天后的一个时间戳的函数,程序的关键是,他可以不去算周六日哦。如果你有别的需求。可以改成N天的哦。反正就不算周六日。哈哈。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
//方法一: <?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 ; } |