PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




localtime

Name

localtime — Returns an array containing the time components of a UNIX timestamp.

Synopsis

array localtime([timestamp][, associative]);
int timestamp (optional): UNIX timestamp
bool associative (optional): Whether to return an associative or indexed array

Returns

Array of time components; FALSE on error

Description

localtime() executes the system's localtime() system call and returns its results in a PHP array. If the associative parameter given is TRUE, the returned array will be an associative array with the key names from the following table; otherwise, the returned array will be indexed starting from 0. If no argument is given for associative , the default is FALSE.

The following table describes the elements of the returned array.

Indexed Key Associative Key Value
0 tm_sec Seconds (0-59, but can be as high as 61 for leap seconds)
1 tm_min Minutes (0-59)
2 tm_hour Hours (0-23)
3 tm_mday Day of the month (1-31)
4 tm_mon Month (0-11)
5 tm_year Year (since 1900)
6 tm_wday Day of the week (0-6; Sunday is 0)
7 tm_yday Day of the year (0-365; Jan 1 is 0)
8 tm_isdst 1 if Daylight Saving Time, 0 otherwise


Version

PHP 4

Example

Example 204. Get the time components in an array

/* When executed at 22:52 April 19, 2001, the following
 * code produced this output:
 *
 * Indexed array of the current time:
 * Array
 * (
 *     [0] => 26
 *     [1] => 52
 *     [2] => 22
 *     [3] => 19
 *     [4] => 3
 *     [5] => 101
 *     [6] => 4
 *     [7] => 108
 *     [8] => 1
 * )
 * Associative array of 2 PM April 30 1981:
 * Array
 * (
 *     [tm_sec] => 0
 *     [tm_min] => 0
 *     [tm_hour] => 14
 *     [tm_mday] => 30
 *     [tm_mon] => 3
 *     [tm_year] => 81
 *     [tm_wday] => 4
 *     [tm_yday] => 119
 *     [tm_isdst] => 1
 * )
 */

echo "Indexed array of the current time:\n";
$time_array = localtime(time());
print_r($time_array);

echo "Associative array of 2 PM April 30 1981:\n";
$time_array = localtime(mktime(14, 0, 0, 4, 30, 81), 1);
print_r($time_array);



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.