Reputation:
I want to show up the time over my website based over the location of the user, let’s say if user one browsing the website is from USA than the time should be what is in USA currently and same for China etc. and all.
I was wondering if there exists a JavaScript plugin for it but I didn’t find any as dynamic as I want, my requirements include:
Is this possible, a way around to achieve it?
Upvotes: 0
Views: 148
Reputation: 21881
Wouldn't this be enough?
html
<span id="time"></span>
js
$(function() {
var time = $("#time");
function getTime() {
var now = new Date(),
hours = now.getHours(),
minutes = now.getMinutes(),
seconds = now.getSeconds();
return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
}
setInterval(function() {
time.text(getTime());
}, 1000);
});
Upvotes: 1
Reputation: 5351
Just putting out the local system time of the user isn't enough?
If you want a server based solution, please take a look at the solution here. You have to find out the users timezone first and then manipulate the server time with an offset from the timezone using $dt->setTimezone(new DateTimeZone("Europe/Berlin"));
.
Upvotes: 0