Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

411
Views
When will my cookie actually expire?

I have an ASP.NET application running on a server in California. The server's current time is:

  • 7/20/2015 14:00 UTC-08:00

Bob is connected to my server. Bob is in Texas. His current time is:

  • 7/20/2015 16:00 UTC-06:00

My application creates a cookie and set its expiration date.

var name = "MyName";
var value = "MyValue"
var hoursToLive = 24;

var myCookie = new HttpCookie(name )
{
    Value = value,
    Expires = DateTime.Now.AddHours(hoursToLive)
};

Will the cookie expire in 24 hours, or will it expire in 22 hours due to the time difference between Bob and the server? I know that DateTime.Now uses the server's local time, but I am unclear as to how browsers decide that a cookie is expired (specifically, what time zone is used to determine expiration).

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cookies do include a timezone information with the expires header (mostly GMT), which makes it quite simple for the client to cope with the offset to the server's actual timezone.

Example: expires=Mon,20-Jul-2015 22:00:00 GMT if 2015-07-20 14:00:00 UTC-8 is the server's time. When the client or server decides whether the cookie is expired or not, it will compare it to the associated GMT time.

I dug deeper into the code of System.Web.HttpCookie, and found the relevant code in GetSetCookieHeader():

        if (_expirationSet && _expires != DateTime.MinValue) {
            s.Append("; expires=");
            s.Append(HttpUtility.FormatHttpCookieDateTime(_expires));
        }

Where HttpUtility.FormatHttpCookieDateTime() returns a UTC timestamp (with no offset, which doesn't matter because the offset would be zero).

Greenwich Mean Time (GMT) and Coordinated Universal Time (UTC) can, for most purposes, be considered the same. You can read more about this here.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!