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.
Asked
Active
Viewed 271 times
0
-
javascript is a client side language.. so it is based on the local settings of the user.. so please provide more details about your problem – mishu Oct 13 '11 at 11:11
-
just came across this code **new Date().getTimezoneOffset()/60;** lets see if this works properly – Sibu Oct 13 '11 at 11:12
-
Maybe this helps: http://www.mtdev.com/2002/06/use-php-and-javascript-to-display-local-time – Keenora Fluffball Oct 13 '11 at 11:12
-
See also http://stackoverflow.com/questions/630321/how-do-you-retrieve-the-client-users-time-zone-for-a-web-application and http://stackoverflow.com/questions/2419808/how-to-get-the-current-time-timezone-of-the-user-visiting-my-website – Herbert Oct 13 '11 at 11:14
1 Answers
2
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>")

SW4
- 69,876
- 20
- 132
- 137