Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



Programming PHP    (ISBN: 1565926102)


 

 List Price: $39.95
 Our Price: $27.97
 Used Price: $18.84

 Release Date: March, 2002
 Manufacturer: O'Reilly & Associates (Paperback)
 Sales Rank: 1,282

 Author: Rasmus Lerdorf, Kevin Tatroe









More Info

 Time 2003-07-03 14:20:16
  php 
Category: source:php:math
Description: Some examples on creating and comparing timestamps with php.
Platform: all
Author: detour
Viewed: 8044
Rating: 3.9/5 (28 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
time.php
<?php
/* time.php by detour@metalshell.com
 *
 * Some examples on creating and comparing timestamps
 * with php.
 *
 * http://www.metalshell.com/
 *
 */


// Retrieve the number of seconds since the Unix Epoch (January 1, 1970)

$curtime = time();

/* Format the date to be human readable.  The date function converts
   specific characters into readable words and numbers. */
$curdate = date("F j, Y h:i:s A", $curtime);

print "The current date is $curdate<br>";

/* Often dates are stored in readable format however they have to be
   converted back into a timestamp to compare times.  PHP provides the
   strtotime() function that will convert most any readable date format
   into a Unix timestamp. */
print "$curtime should equal " . strtotime($curdate) . "<br>";

// Sleep five seconds to compare two times.

print "Sleeping for five seconds.<br>";
sleep(5);

print "This program has been running for " . (time() - $curtime) . 
      " seconds.<br>";

/* You can also create your own timestamp from a time using mktime(). 
   The format is int mktime(hr, min, sec, month, day, year, is_dst)
   is_dst is used define whether or not to use daylight savings. 
   Any of these values may be ommitted. */

print "The timestamp for 12am on 11/26/81 is " . mktime(0,0,0,11,26,81) . 
      "<br>";

/* If you are bench marking a program microtime is probably what you 
   will want to use.  It returns microseconds and a normal timestamp divided 
   by a space. */
list($msec, $sec) = split(" ", microtime());
$fltime = (float)$msec + (float)$sec;
print "This program ran exactly " . ($fltime - $curtime) .
      " seconds<br>";

?>
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?