Jack
Jack

Reputation: 16724

Get current date from user's computer on web site

How can I get the user's current date running web site? DateTime.Now will return server's rather user. I guess I'll get some luck by evaluating javascript using C#, I want to know if there's a more elegant way to do that.

Upvotes: 1

Views: 295

Answers (2)

Moises Quintero
Moises Quintero

Reputation: 76

Consider that javascript executes on client side, so you will retrieve date of computer user. While on the application running on server side you will get date of server.

It depends what do you need to do, and where you will use the date.

If the server needs to know the date of user, then you will have to send it in your request.

Upvotes: 2

George Chen
George Chen

Reputation: 6939

Open solution is to use the request ip address to get Geolocation, then derives the timezone and local time from server side. This might not be very reliable. Another option is to always have the local time sent with each request.

Upvotes: 1

Related Questions