On my website, I use the php time() function to display the time. A week ago I compared the time difference between the time returned by the time() function and the time on my computer(I use windows). The time difference was about a minute and 10 seconds but now I checked again and the time difference has grown to a minute and 50 seconds. Can anyone explain how this is possible?
-
1You aren't clear about whether your computer is acting as the server that is executing your php time function. Is it your computer or is it a server somewhere? – Don Dickinson Aug 24 '10 at 13:27
-
Do you happen to be running this in a virtual machine? – Pekka Aug 24 '10 at 13:29
-
3Call your NASA dudes to synchro your space shuttle timer – Piotr Müller Aug 24 '10 at 13:30
-
I just checked and yes the time() function is returning the time on my server and that time is different from windows time. Though it is different, the difference should always remain the same, but its not? – ha1ogen Aug 24 '10 at 14:02
4 Answers
Set your time zone by date_default_timezone_set()
I'm not sure this would help.

- 5,323
- 5
- 55
- 82
On some Linux dystros time is resynced via NTP on system restart only. You may install ntp daemon which will keep time delta in <10ms constantly.

- 6,483
- 2
- 34
- 47
I think this confusing made from your computer and server. One week you may compare with your computer time and now you check with server time. Make sure about this. Because server time is differ from our local computer time.

- 3,221
- 5
- 28
- 38
first store time and date of message post in mysql database using predefined function date()
for getting our local time we have to use date_default_timezone_set()
function before date()
date_default_timezone_set("Asia/Calcutta");
$massege_post_time=date("H:i:s Y-m-d ");
Time And Date will store in database like 15:56:28 2018-08-09
Where H= 15(24 hour system) i=56(minute) s(second)=28
Y(year)=2018 m(month)=08, d(day)=09
I answer here for previously asked question on this site xx time ago function doesn't work
you can get more idea about it.
try this time ago in php like facebook
I hope this will be helpful for you

- 2,051
- 9
- 30
- 41

- 1
- 5