localtime()
We can get local time with date, month year etc. ( array output ) by using localtime() function in PHP.
Here is the syntax.
localtime();
Example code
print_r(localtime());
The output of above code is here
Array
(
[0] => 26
[1] => 16
[2] => 6
[3] => 15
[4] => 8
[5] => 124
[6] => 0
[7] => 258
[8] => 0
)
We can get better output by using is_associative to true. We will get a set of keys and associated data. Here is an example.
print_r(localtime(time(),true));
The output is here. Array
(
[tm_sec] => 26
[tm_min] => 16
[tm_hour] => 6
[tm_mday] => 15
[tm_mon] => 8
[tm_year] => 124
[tm_wday] => 0
[tm_yday] => 258
[tm_isdst] => 0
)
We can change the time zone set and check the return like this.
date_default_timezone_set('Asia/Kolkata');
print_r(localtime(time(),true));
The ouput is hereArray
(
[tm_sec] => 26
[tm_min] => 46
[tm_hour] => 11
[tm_mday] => 15
[tm_mon] => 8
[tm_year] => 124
[tm_wday] => 0
[tm_yday] => 258
[tm_isdst] => 0
)
Refresh this page and see how the data is changing
←PHP Date Functions
GMT/UTC date/time →
Date formats for Date() →
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com