Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

localtime()

Example

Print local time as both an indexed and an associative array.

<?php
print_r(localtime());
echo “<br><br>”;
print_r(localtime(time(),true));
?>

Definition and Usage

The localtime() function returns the local time.

Syntax

localtime(timestamp, is_assoc)

Parameter Values

 

Parameter

Description

timestamp

Optional. Specifies a Unix timestamp, defaulting to the current local time (time()) if no timestamp is provided.

is_assoc

Optional. Specifies whether to return an associative or indexed array. FALSE returns an indexed array (default), while TRUE returns an associative array. 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: Indicates if daylight saving time is in effect

Technical Details

Return Value:

Returns an array containing the components of a Unix timestamp.

PHP Version:

4+

PHP Changelog:

PHP 5.1: Now triggers E_STRICT and E_NOTICE time zone errors.