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 codeprint_r(localtime());The output of above code is hereArray ( [0] => 59 [1] => 7 [2] => 10 [3] => 18 [4] => 0 [5] => 121 [6] => 1 [7] => 17 [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] => 59 [tm_min] => 7 [tm_hour] => 10 [tm_mday] => 18 [tm_mon] => 0 [tm_year] => 121 [tm_wday] => 1 [tm_yday] => 17 [tm_isdst] => 0 )We can change the time zone set and check the return like this.date_default_timezone_set('Asia/Kolkata');
The ouput is here |