tags:

views:

42

answers:

2

Does Date.today() return the current date based on the server's date? If so, how can I get the correct date for a user?

A: 

You can use ajax to send back the user date created by javascript on the client machine.

vurte
That's assuming the LOCALE or timezone information is set correctly on the user's machine.
Greg
@Greg: And time too.
Mladen Jablanović
Or you can use geotargeting to match the ip of the client machine with timetables.
vurte
Wouldn't VPN confuse geotargeting? Or a corporate machine behind a company router? Not all machines are directly attached to the internet and the machine's IP or timezone might not be the same IP or timezone as the router seen by the server software.
Greg
I think you can use this 2 ways and ask the user if the calculated time is really his current time.Other ways, if he has not set his time correctly on his pc AND in the same time uses proxy or vpn (which is located in a different country or timezone), I now can't think of an other way ...
vurte
"ask the user if the calculated time is really his current time" - I like that. If you get it right then there's a touch of magic going on. If it's wrong, hopefully the user will appreciate that the code tried, and will then correct whatever is wrong, either in the app's settings or on their machine.
Greg
A: 

The best way is to ask the user what their timezone is. You can try to determine via software without asking them, but if the user has not set up their machine correctly you'll get an incorrect response. By asking you're giving them the choice to give a correct answer, or to lie to you if they are so inclined.

You might want to ask the same question over on SO's sibling User Interface site.

Greg