How to get the exact local time of client?

user850234 picture user850234 · May 18, 2012 · Viewed 151.8k times · Source

What is the best method to get the clients local time irrespective of the time zone of clients system? I am creating an application and i need to first of all get the exact time and date of the place from where the client is accessing. Even detecting the ip address of client system has a drawback or detecting the time zone of client system may be risky at times. So, is there any way out which could be really reliable and not vulnerable to error because displaying wrong time and date to client is something very embarassing.

Answer

Madara's Ghost picture Madara's Ghost · May 18, 2012

In JavaScript? Just instantiate a new Date object

var now = new Date();

That will create a new Date object with the client's local time.