I'm trying to write cookies from my website and I'm trying to figure out what implications timezones has over the HttpCookie.Expire property. Should I be passing DateTime.Now.AddDays(1)
or DateTime.UtcNow.AddDays(1)
or the users's timezone plus a day?
Asked
Active
Viewed 2,297 times
6

ajma
- 12,106
- 12
- 71
- 90
1 Answers
11
If you use a local time, .NET will automatically convert it to GMT when outputting it to the client.
So it doesn't matter for the cookie, but I do suggest to always work with UTC, so at least you can assume that in your data the timezone offset is always 0.

Gideon
- 18,251
- 5
- 45
- 64
-
The [documentation for system.net.cookie.expires](https://msdn.microsoft.com/en-us/library/system.net.cookie.expires(v=vs.110).aspx) backs up your answer with respect to that class, but the [documentation for system.web.httpcookie.expires](https://msdn.microsoft.com/en-us/library/system.web.httpcookie.expires(v=vs.110).aspx) contains no such information. Is there any other documentation that confirms that the behaviour is the same? (I don't know why there are two different classes, but that's beside the point) – David P Sep 06 '17 at 12:38
-
Never mind my previous question. It is answered in this SO answer: https://stackoverflow.com/a/31527059/1009155 – David P Sep 06 '17 at 13:01