PHP: A Simple Function For Getting The Current Nigeria Local Time

If you ever noticed, the PHP date() function returns an incorrect time, if you’re not in the same country as your server. The date () function has been built to return only the date/time of the server and not the date/time of the country you are. I wrote this script to get the current local time in Nigeria alone, you can also further modify it to your taste, or perhaps change the time zone in date_default_timezone_set(‘Africa/Lagos’); to your timezone( the timezone of your country, if you’re not in Nigeria but also not getting a correct time when you call the date() function).

How it works

Thedate_default_timezone_set(‘Africa/Lagos’); sets the default timezone to Africa/Lagos which happens to be Nigeria timezone. The $time variable stores the time format which the function returns each time the function is being called. We can further customize it to echo a greeting message alongside the time

You can replace the message in the $message variable with a welcome message that you’d prefer; and you can simply call the function and echo the current time in Nigeria with echo get_ng_time(); .

Hope this helps, Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *