Hi All,
herez my issue:
i have a server which has a ET time setting on it.
i have clients who will be accessing my web application from both ET and IST time zones.
ET is 7 hours behind the GMT.
IST is 5.5 hours ahead of GMT.
I should display the right time depending on which timezone the client is logging into my web application.
in my current code i am taking UTC (GMT) as the key time. Here is my code which does it.
//Get the user's timezone
TimeZone myTime = TimeZone.CurrentTimeZone;
TimeSpan myTimeSpan = myTime.GetUtcOffset(
new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day));
DateTime today = DateTime.UtcNow;
DateTime todayServer = DateTime.UtcNow;
DateTime retDateTime = DateTime.Now;
//Localtime = UTC + UTC Offset
todayServer = todayServer.Add(myTimeSpan);
int compare = DateTime.Compare(todayServer, today);
switch(compare)
{
case 0: // GMT
retDateTime = today;
break;
case 1: // Local Time
retDateTime = todayServer;
break;
case -1: // Server Time
retDateTime = todayServer;
break;
default:
break;
}
return retDateTime;
----
but everytime i get only one timezone setting: ET. because the following statement returns -1.
DateTime.Compare(todayServer, today);
where todayServer returns the ET and today returns the GMT/UTC.
How can i modify my above code so that it handles both ET and IST issue?
TIA
Mohith