dev.e.loper
dev.e.loper

Reputation: 36044

In web application, how does DateTime.Now know the local time for user?

According to this DateTime.Now vs. DateTime.UtcNow you store date time information in UTC and show it to user as DateTime.Now. If it is on web application, how does DateTime.Now know about user's location and adjusts UTC time accordingly? Is location inferred from header information that user passes in?

Upvotes: 2

Views: 1184

Answers (3)

James Johnson
James Johnson

Reputation: 46057

DateTime.Now returns the current time according to the server, not the client.

Upvotes: 2

The Evil Greebo
The Evil Greebo

Reputation: 7138

As Blake said, it doesn't.

If a server is calculating the current time for the end user, it must be based on information that user has provided. Otherwise, you typically would use javascript to provide the current date/time reference based on the local machine's clock.

Upvotes: 4

Doozer Blake
Doozer Blake

Reputation: 7797

DateTime.Now does not know the user's location and adjust for it. It is based off the server the site is running on.

Upvotes: 7

Related Questions