Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

The strftime function returns a date in a particular format. If the optional timestamp
argument is left out, the current time will be used. Language-dependent strings will be set
according to the current locale, which may be changed with the setlocale function. The
format string may contain codes that have special meaning and begin with a percentage
sign. Other characters are passed through unchanged. See Table 11.4 for a list of format
codes.


<?
//prints something like
//Monday, 01/01/01 16:04:12
print(strftime("%A, %c"));
?>


integer strtotime(string date, integer now)


The strtotime function attempts to parse a string containing date and time, returning the
timestamp for it. If partial information is provided in the date argument, the missing
information will be drawn from the now argument. You may leave out the now argument
to use the current time.


<?
//create a reason description
//of a date
$time = "Feb 18, 1970 3AM";


//get its timestamp
$ts = strtotime($time);


//print it to verify that it worked
print(date("h:i A l F dS, Y", $ts));
?>


integer time()


Use time to get the current timestamp.


<?
print(time());
?>


Alternative Calendars

Free download pdf