Your cookie will expire at exactly the same moment in time for everyone...
...just at different local times shown on their clocks based on their timezones. So for example, people who got cookies at exactly the same moment in California and Texas, those users will see their cookies expired at the same moment in time, just not the same time shown on their clocks. For Bob it will be 4:pm
but in California it will be 2:pm
. Same point in time, just different clocks at different times of the day for each person using your website.
Cookies all save DateTime expiration values in UTC
or Universal Coordinated Time
which is in Greenwich, London, UK (England). When users store cookies in their browsers, all their cookie expiration date-times are in ISO-UTC format and have a "Z" or "GMT" at the end to indicate they are using this UTC value. Even though they may look different for different local times around the world, they include an offset that maps them back to UTC. This means when you set a DateTime for two different users at the same time in different time zones, they both will expire at the same point in time, just not the same local time shown on clocks in both zones.
However...
If you wanted each person's cookie to expire at say midnight relative to their time zone, then yes, you would need to first get the local time of midnight for their local computer using JavaScript, then translate that to UTC. Create a cookie in JavaScript from that using document.cookie
. Now they havea cookie that ends at midnight only in their time zone.
Another option...
If you wanted to have everyone around the world have cookies that expire relative to a specific timezone clock at say, midnight in California, then yes...you would need to get the exact datetime in California you want the rest of the world to use in your cookie logic and translate that to UTC datetime. Store that value on the server, then set it as the cookie expiration for all user cookies visiting your website. When midnight in California occurs, everyone's cookie around the world expires at the same time again, but to that same UTC value which matches midnight in California.