php - Countdown timer on my website changes if I change my computer's time?


Hi I need help regarding the following issue:

My website has a timer countdown running. Actually in my admin panel I set a date and time for a process to begin and when i hit on save the timer countdown starts in my website.

Example : Say now my current time is 1pm. Now for example in my admin panel I am creating an event now. The start of the event is tomorrow 1pm. So now in my admin panel I select the start time of event to tomorrow 1 pm. Now the time remaining for the event is 24 hours. So now in my website the countdown timer starts for the event like :Time left for the event : 24h:0m:0s and this timer goes in decreasing order. Now the issue is that the timer is taking the time from my computer. If I change the time on my computer, the count down timer on my website also changes.

Please help me out regarding this on how to use the server time for my website's timer so the time is same for all the users irrespective of their computer's date and time.

I also heard a concept of stop watch?

Please help me out




If your code is on server the only reason for showing local time is you are using Javascript for time because Javascript fetch time from local system.




just set these at top of your php code and calculate or do whatever you want with it afterwards

date_default_timezone_set('Europe/London'); //or Asia/India or any other
$login_date=date("Y-m-d H:i:s"); 



JavaScript traditionally runs client-side, meaning in the user's browser whereas PHP runs server side, ie. it will fetch time from your server. In your case, you need the time to be same for all users of your website which means you need a server side code

In short:

  1. JavaScript Timer
    • Runs client side
    • You are using this
    • Example code
  2. PHP Timer
    • Runs server side
    • You need this
    • Example code

People are also looking for solutions to the problem: php - cvc-complex-type.2.4.a: Invalid content was found starting with element 'foo'


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.