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] => 0 [1] => 22 [2] => 2 [3] => 23 [4] => 9 [5] => 117 [6] => 1 [7] => 295 [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] => 0 [tm_min] => 22 [tm_hour] => 2 [tm_mday] => 23 [tm_mon] => 9 [tm_year] => 117 [tm_wday] => 1 [tm_yday] => 295 [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 here

Array ( [tm_sec] => 0 [tm_min] => 52 [tm_hour] => 7 [tm_mday] => 23 [tm_mon] => 9 [tm_year] => 117 [tm_wday] => 1 [tm_yday] => 295 [tm_isdst] => 0 )

Refresh this page and see how the data is changing

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Your Rating


Google+



More On Date Object

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer