03c01-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 30 行

PHP
30
字号
<?php// Set the default timezone to US/Easterndate_default_timezone_set('US/Eastern');// Will return the number of days between the two dates passed infunction count_days($a, $b) {	// First we need to break these dates into their constituent parts:	$a_dt = getdate($a);	$b_dt = getdate($b);		// Now recreate these timestamps, based upon noon on each day	// The specific time doesn't matter but it must be the same each day	$a_new = mktime(12, 0, 0, $a_dt['mon'], $a_dt['mday'], $a_dt['year']);	$b_new = mktime(12, 0, 0, $b_dt['mon'], $b_dt['mday'], $b_dt['year']);	// Subtract these two numbers and divide by the number of seconds in a	//  day.  Round the result since crossing over a daylight savings time	//  barrier will cause this time to be off by an hour or two.	return round(abs($a_new - $b_new) / 86400);	}// Prepare a few dates$date1 = strtotime('12/3/1973 8:13am');$date2 = strtotime('1/15/1974 10:15pm');$date3 = strtotime('2/14/2005 1:32pm');// Calculate the differences, they should be 43 & 11353echo "<p>There are ", count_days($date1, $date2), " days.</p>";echo "<p>There are ", count_days($date2, $date3), " days.</p>";?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?