I am confused with the DateTime component of .net. The server is running in UTC +4 and my clients are in different timezones. So the time on the server is in UTC+4 mode. I’ve already tried to cast it to UniversalTime and to send it in ToBinary before sending it to client, but on client machine the code looks like
if ((Program.license.EndDate.ToUniversalTime()
- DateTime.Now.ToUniversalTime()).TotalMinutes <= 5)
{
//dosomething
}
still works wrong.
Thank you for your help.
You have to know the DateType of the DateTime being sent from the client (Local, Universal, or Unspecified). If you try to cast an Unspecified type as universal, from what I understand, it will be handled as local time. (Someone please correct me if I am wrong.)
Best practice with server/client dates and times is to always use UTC. In .Net use
DateTime.UtcNowinstead ofDateTime.Now.ToUniversalTime().