PHP localtime() Function
In this chapter you will learn:
- Definition for PHP localtime() Function
- Syntax for PHP localtime() Function
- Parameter for PHP localtime() Function
- Return value for PHP localtime() Function
- Example for PHP localtime() Function
Definition
The localtime() function returns the local time.
Syntax
PHP localtime() Function has the following syntax.
localtime(timestamp,is_assoc);
Parameter
Parameter | Is Required | Description |
---|---|---|
timestamp | Optional. | Unix timestamp that defaults to the current local time, time(), if no timestamp is specified |
is_assoc | Optional. | whether to return an associative or indexed array. |
Possible values for is_assoc.
- FALSE - means the array returned is an indexed array.
- TRUE - means the array returned is an associative array. FALSE is default.
The keys of the associative array are:
- [tm_sec] - seconds
- [tm_min] - minutes
- [tm_hour] - hour
- [tm_mday] - day of the month
- [tm_mon] - month of the year (January=0)
- [tm_year] - Years since 1900
- [tm_wday] - Day of the week (Sunday=0)
- [tm_yday] - Day of the year
- [tm_isdst] - Is daylight savings time in effect
Return
PHP localtime() Function returns an array that contains the components of a Unix timestamp.
Example
Print local time as an indexed and as an associative array:
<?php/*from j a v a 2s . c o m*/
print_r(localtime());
echo "\m";
print_r(localtime(time(),true));
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP microtime() Function
- Syntax for PHP microtime() Function
- Parameter for PHP microtime() Function
- Return value for PHP microtime() Function
- Example - Return the current Unix timestamp with microseconds
Home » PHP Tutorial » PHP Date Functions