Home Tutorial Php Phpdate localtime()

 
 

Share on Google+Share on Google+
localtime()
Posted on: August 28, 2009 at 12:00 AM
Advertisement
The following example of localtime is used for resulting a local timestamp.

PHP localtime() Format

localtime() returns an array containing the time components of a Unix timestamp. It returns an array identical to that of the structure returned by the C function call.

Syntax of localtime() Function PHP

localtime(timestamp,is_associative)

Parameter & Description of localtime() Function PHP

timestamp - timestamp is optional parameter. It specifies the date or time to be formatted, it returns the local time if it is not formatted. 

is_associative - is_associative is optional that specifies whether to return an associative or indexed array. If set to false the array returned is an indexed array. If set to true then the array returned is 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] - Is daylight savings time in effect

Example: Example without and with associative arrays:

<?php
print_r(localtime());
echo("<br /><br />");
print_r(localtime(time(),true));
?>

The output of the code above could be:
Array
(
[0] => 15
[1] => 23
[2] => 09
[3] => 14
[4] => 12
[5] => 115
[6] => 5
[7] => 17
[8] => 4
)

Array
(
[tm_sec] => 15
[tm_min] => 23
[tm_hour] => 09
[tm_mday] => 14
[tm_mon] => 12
[tm_year] => 115
[tm_wday] => 5
[tm_yday] => 17
[tm_isdst] => 4
)

Advertisement

Related Tags for localtime():


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 28, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com