Jump to content

PHP date and time function is not showing correct time on my local system


Ponel

Recommended Posts

PHP date and time function is not showing correct time on my local system

I have the following php code

date_default_timezone_set("Africa/Lagos");

$date = date('d-m-y h:i:s');

echo "Server Time ".$date ."<br>";

echo "The time is " . date("h:i:sa")."<br>";

$current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa')));

echo "Current time1: ".$current_datetime . "<br>";

 

Output

Server Time 21-05-21 09:55:39
The time is 09:55:39am
Current time1: 2021-05-21 09:55:39

 

Expected Output

Server Time 21-05-21 10:55:39
The time is 10:55:39am
Current time1: 2021-05-21 10:55:3

 

Any help would be appreciated.

 

Edited by Ponel
Link to comment
Share on other sites

Either (a) you're not in Africa/Lagos, which would be a silly mistake to make, (b) your timezone database is out of date, but probably not given that Africa/Lagos doesn't do DST, and/or (c) your server's clock is set incorrectly.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.