I tried to send the user back to the client in the post, put the cookie and then return it to the server, but it is problematic for google, because they do not have cookie.
Here is the function:
I thought to find the offset based on the calture, but I do not know how to do it.
A few things:
- You are doing too much work to get at the UTC time. Just use DateTime.UtcNow.
- Scripting postbacks are a thing of the past. You've already shown you're using jquery, so just do an ajax post to send it to the server. That will solve your google issue as well.
- If your first page needs that, then send the UTC time and convert it on the client - or do an ajax get to retrieve it.
- Keep in mind that the user can set their clock to whatever timezone they want, and that the offsets can and will change for many users because of daylight savings time / summer time. If you keep their offset in a permanent cookie, you will have the wrong time when they come back after the change. Make sure it's in a temporary cookie, and it's probably something you will want to reset often.
- You say that you are processing data using the client's local time? Can you elaborate on what for? That is a very dangerous thing to do since local times can be ambiguous. You should probably be processing based on UTC. If you need the client's offset while processing, you should use a DateTimeOffset on the server. Review here.