From faa617e4fd49d95b9b5906a818c8dc9c88c1dde8 Mon Sep 17 00:00:00 2001 From: Ron Chmara Date: Sat, 10 Mar 2001 23:32:57 +0000 Subject: [PATCH] Updating per errata notes, adding examples. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@43153 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/datetime.xml | 62 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/functions/datetime.xml b/functions/datetime.xml index bfc1c89119..7f6ea46667 100644 --- a/functions/datetime.xml +++ b/functions/datetime.xml @@ -251,6 +251,31 @@ $nextyear = mktime (0,0,0,date("m"), date("d"), date("Y")+1); + + Some examples of date formatting. Note that + you should escape any other characters, as any which currently + have a special meaning will produce undesirable results, and + other characters may be assigned meaning in future PHP versions. + When escaping, bu sure to use single quotes to prevent characters + like \n from become newlines. + + + <function>Date</function> Formatting + + +/* Today is March 10th, 2001, 5:16:18 pm */ +$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm +$today = date("m.d.y"); // 03.10.01 +$today = date("j, g, Y"); // 10, 3, 2001 +$today = date("Ymd"); // 20010310 +$today = date('h-i-s, j-m-y, it is w Day z '); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01 +$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day. +$today = date("D M j g:i:s T Y"); // Sat Mar 10 15:16:08 MST 2001 +$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:17 m is month +$today = date("H:i:s"); // 17:16:17 + + + To format dates in other languages, you should use the setlocale and strftime @@ -335,6 +360,18 @@ $nextyear = mktime (0,0,0,date("m"), date("d"), date("Y")+1); + + + <function>getdate</function> example + + +$today = getdate(); +$month = $today[month]; +$mday = $today[mday]; +$year = $today[year]; +echo "$month $mday, $year"; + + @@ -548,7 +585,7 @@ echo gmstrftime ("%b %d %Y %H:%M:%S", mktime (20,0,0,12,31,98))."\n"; - "tm_year" - Year, not y2k compliant + "tm_year" - Years since 1900 @@ -592,6 +629,29 @@ echo gmstrftime ("%b %d %Y %H:%M:%S", mktime (20,0,0,12,31,98))."\n"; function is only available on operating systems that support the gettimeofday() system call. + + Both portions of the string are returned in units of seconds. + + <function>microtime</function> example + +function getmicrotime(){ + list($sec, $usec) = explode(" ",microtime()); + return ($sec + $usec); + } + +$time_start = getmicrotime(); + +for ($i=0; $i < 1000; $i++){ + //do nothing, 1000 times + } + +$time_end = getmicrotime(); +$time = $time_end - $time_start; + +echo "Did nothing in $time seconds"; + + + See also time.