Sibu
Sibu

Reputation: 42

How to get location based time?

i am working on javascript which displays time based on location, that is if a user logs on from china it should display their local time or a user from india it should display their code.No matter what, i am not able to get the code.pls someone help.

Upvotes: 0

Views: 275

Answers (1)

SW4
SW4

Reputation: 71170

You can get the users local time in JS with:

  var currentTime = new Date()
  var hours = currentTime.getHours()
  var minutes = currentTime.getMinutes()

  if (minutes < 10)
  minutes = "0" + minutes

  document.write("<b>" + hours + ":" + minutes + " " + "</b>")

Upvotes: 2

Related Questions