Hi, I want to get the date and time of user's local system. How can I accomplish that in asp.net mvc? I am using mvc 1.0. Thanks.
+1
A:
There's no way you can do that in server-side asp.net mvc code.
Either you prompt the user with DtropDown list of all timezones and let him pick it from the list and second option is to capture local system time in client-javascript and send it to server over an AJAX request or a post-back.
In fact there's one more way - You can capture the IP of the user's machine and find out the country to which that IP belongs to and pick the TimeZone of that country. You can use MaxMind GeoIP database which can help you do this very easily.
this. __curious_geek
2010-09-16 06:45:06
Hi, I tried this approach too and to set the time with javascript and get it in server side, I used cookies and setTimeInterval method. This normally works fine but in case of ajax forms I dont know why it sends old time with cookies. Can you help with this? Thanks.
gaurav
2010-09-16 06:48:06
@gaurav - Why are you sending the time in cookies? Why not just grab it once and then keep track of it for that user or session?
Justin
2010-09-16 06:53:51
Got it, Thanks you all for giving your valuable time. :)
gaurav
2010-09-16 06:59:04
+2
A:
I think that you need to capture it via JavaScript and then send it back to the server (eg. using AJAX).
In the JavaScript: var d = new Date()
will capture what you need.
Justin
2010-09-16 06:46:44
Hi Justin, I tried this approach too and to set the time with javascript and get it in server side, I used cookies and setTimeInterval method. This normally works fine but in case of ajax forms I dont know why it sends old time with cookies. Can you help with this? Thanks
gaurav
2010-09-16 06:51:32