1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# //Default time zone date_default_timezone_set( 'PRC' );
echo "Today: " , date ( 'Y-m-d H:i:s' ), "\n" ;
echo "Tomorrow: " , date ( 'Y-m-d H:i:s' , strtotime ( '+1 day' )), "\n" ;
<p class="line number8 index7 alt1" style="background-image:none;border:0px;float:none;margin:0px;padding:0px 1em;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"><code class="php spaces" style="font-size:1em;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;min-height:auto;">
echo date ( 'Y-m-d H:i:s' , strtotime ( "+1 day" , strtotime ( '2017-11-11' ))), "\n" ;
echo date ( 'Y-m-d H:i:s' , strtotime ( "+1 day +1 hour +1 minute" )), "\n" ;
?></p>
</td>
</tr></tbody></table>
<p style="margin-top:10px;margin-bottom:10px;color:rgb(51,51,51);">Run results:</p>
<p style="margin-top:10px;margin-bottom:10px;color:rgb(51,51,51);"><span style="color:rgb(0,0,255);">Today: 2017-11-06 18:58:04<br>Tomorrow: 2017-11-07 18:58:04<br>2017-11-12 00:00:00<br>2017-11-07 19:59:04</span></p>
<p style="margin-top:10px;margin-bottom:10px;color:rgb(51,51,51);"> </p>
<p style="margin-top:10px;margin-bottom:10px;color:rgb(51,51,51);"><span style="color:rgb(178,34,34);"><strong>PHP Advanced Calculation of Date and Time Difference</strong></span></p>
<p class="syntaxhighlighter php" style="margin:1em 0px;font-size:1em;"><br></p>
<table border="0" style="background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:1em;min-height:auto;"><tbody style="background:none;float:none;margin:0px;padding:0px;vertical-align:baseline;font-size:1em;min-height:auto;"><tr style="background:none;border-top:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;font-size:1em;min-height:auto;" class="firstRow">
<td class="gutter" style="vertical-align:baseline;background:none;border-width:0px;float:none;margin:0px;padding:0px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:1em;min-height:auto;color:rgb(175,175,175);">##1<p class="line number1 index0 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>2<p class="line number2 index1 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>3<p class="line number3 index2 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>4 <p class="line number4 index3 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>5<p class="line number5 index4 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>6<p class="line number6 index5 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>7<p class="line number7 index6 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>8<p class="line number8 index7 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>9<p class="line number9 index8 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>10<p class="line number10 index9 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>11<p class="line number11 index10 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>12<p class="line number12 index11 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;"></p>
<p class="line number13 index12 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">13</p>
<p class="line number14 index13 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">14</p>
<p class="line number15 index14 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">15</p>
<p class="line number16 index15 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">16</p>
<p class="line number17 index16 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">17</p>
<p class="line number18 index17 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">18</p>
<p class="line number19 index18 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">19</p>
<p class="line number20 index19 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">20</p>
<p class="line number21 index20 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">21</p>
<p class="line number22 index21 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">22</p>
<p class="line number23 index22 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">23</p>
<p class="line number24 index23 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">24</p>
<p class="line number25 index24 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">25</p>
<p class="line number26 index25 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">26</p>
<p class="line number27 index26 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">27</p>
<p class="line number28 index27 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">28</p>
<p class="line number29 index28 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">29</p>
<p class="line number30 index29 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">30</p>
<p class="line number31 index30 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">31</p>
<p class="line number32 index31 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">32</p>
<p class="line number33 index32 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">33</p>
<p class="line number34 index33 alt1" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">34</p>
<p class="line number35 index34 alt2" style="background-image:none;border-width:0px 3px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;margin:0px;padding:0px .5em 0px 1em;text-align:right;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">35</p>
</td>
<td class="code" style="vertical-align:baseline;background:none;border-width:0px;float:none;margin:0px;padding:0px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:1em;min-height:auto;">
<p class="container" style="background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;font-size:1em;min-height:auto;"><br></p>
<p class="line number1 index0 alt2" style="background-image:none;border:0px;float:none;margin:0px;padding:0px 1em;vertical-align:baseline;font-size:1em;min-height:auto;white-space:pre;">##<?php<code class="php plain" style="font-size:1em;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;background:none;border:0px;float:none;margin:0px;padding:0px;vertical-align:baseline;min-height:auto;color:#000000;"> ## //Default time zone date_default_timezone_set( 'PRC' );
echo date ( "Y-m-d H:i:s" ), "\ n" ;
echo date ( 'Y-m-d' , strtotime ( '+1 day' , strtotime ( '2016-09-12' ))), "\n\n" ;
echo strtotime ( '2016-09-12' ), "\n" ;
echo date ( "Y-m-d" , '1473609600' ), "\n" ;
echo date ( "Y-m-d" , ' 1573609600' ), "\n" ;
$d = "2016-09-12 10:12:20" ;
echo date ( "Y-m-d" , strtotime ( "$d +1 day" )), "\n\n" ;
#$year =((int) substr ( "$d"
,0, 4)); //Obtained year
$month =((int) substr ( "$d" ,5,2));
$day =( (int) substr ( "$d" ,8,2));
return mktime (0,0,0, $month , $day , $year );
}
echo date2time( "2016-09-12" ), "\n\n" ;
$date_1 = "2066-09-12" ;
$date_2 = "2016-09-12" ;
$Date_List_a1 = explode ( "-" , $date_1 );
$Date_List_a2 = explode ( "-" , $date_2 );
$d1 = mktime (0,0,0, $Date_List_a1 [1], $Date_List_a1 [2], $Date_List_a1 [0]);
$d2 = mktime (0,0,0, $Date_List_a2 [1], $Date_List_a2 [2], $Date_List_a2 [0]);
$Days = round (( $d1 - $d2 )/3600/24);
## echo "$date_2 -> $date_1 difference: $Days days" , "\n" ;
?>
|