0

Could someone assist me in creating a live database timer.

It will have a start time in database, I am using PHP and am hoping to use js or ajax whatever works best for what I am trying to complete.

I've written some pseudo-like code to illustrate how I plan to do this:

BEGIN

Request server time
// adjust server time with client time

get serverTime
get clientTime

adjustment = serverTime - clientTime
timeData = timeData - adjustment

THEN 
send timeData to server

END
2
  • how about looking into create event. It's like Timex. It just keeps running and running and ... Here is an example stub Commented Oct 27, 2015 at 1:47
  • note, that is for a server time, unrelated to ajax Commented Oct 27, 2015 at 1:54

1 Answer 1

2
<div id="time">
    <span id="hour">hh</span>:<span id="min">mm</span>:<span id="sec">ss</span>
</div>

setInterval(update, 1000);
function update() {
  var date = new Date()

  var hours = date.getHours()
  if (hours < 10) hours = '0'+hours
  document.getElementById('hour').innerHTML = hours

  var minutes = date.getMinutes()
  if (minutes < 10) minutes = '0'+minutes
  document.getElementById('min').innerHTML = minutes

  var seconds = date.getSeconds()
  if (seconds < 10) seconds = '0'+seconds
  document.getElementById('sec').innerHTML = seconds
}

You don't need to use ajax or php you can do it with simple javascript

Sign up to request clarification or add additional context in comments.

1 Comment

However, if I was to not use a server side language an end user can simply edit their systems time which would greatly affect the application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.