Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I host my project in godaddy server.
That server only support U.S. timing so i need to convert that server time to indian time.

How to convert U.S. time to Indian time with daylight changes?
Posted
Updated 27-Sep-15 23:48pm
v2
Comments
Andy Lanng 28-Sep-15 5:49am    
Aren't there several calendars used in India? Which do you need specifically, or is there a single standard one?
Sinisa Hajnal 28-Sep-15 5:51am    
Also, what have you tried?
JOTHI KUMAR Member 10918227 28-Sep-15 7:23am    
DateTime utc = DateTime.UtcNow;
// DateTimeOffset localServerTime = DateTimeOffset.Now;

var easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime easternTime = TimeZoneInfo.ConvertTimeFromUtc(utc , easternZone);


TimeZone zone = TimeZone.CurrentTimeZone;
DaylightTime time = zone.GetDaylightChanges(DateTime.Today.Year);
//// DateTime eastern = TimeZoneInfo.ConvertTimeFromUtc(utc, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(utc, tzi);
BillWoodruff 28-Sep-15 6:49am    
I would be surprised that any server today would not provide UTC time data ... however, given how dumb GoDaddy has been in the past, I believe you.
JOTHI KUMAR Member 10918227 28-Sep-15 7:23am    
i need a standard format. and i have tried
DateTime utc = DateTime.UtcNow;
// DateTimeOffset localServerTime = DateTimeOffset.Now;

var easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime easternTime = TimeZoneInfo.ConvertTimeFromUtc(utc , easternZone);


TimeZone zone = TimeZone.CurrentTimeZone;
DaylightTime time = zone.GetDaylightChanges(DateTime.Today.Year);
//// DateTime eastern = TimeZoneInfo.ConvertTimeFromUtc(utc, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(utc, tzi);

Set the locale to the one you want in the web.config and any datetime\currency etc formatting should adhere to that assuming you have coded your site correctly.

https://msdn.microsoft.com/en-gb/library/hy4kkhe0(v=vs.85).aspx[^]
 
Share this answer
 
Consider to use TimeZoneInfo.ConvertTime Method[^]:

C#
DateTime hwTime = new DateTime(2007, 02, 01, 08, 00, 00);
try
{
   TimeZoneInfo hwZone = TimeZoneInfo.FindSystemTimeZoneById("Hawaiian Standard Time");
   Console.WriteLine("{0} {1} is {2} local time.", 
           hwTime, 
           hwZone.IsDaylightSavingTime(hwTime) ? hwZone.DaylightName : hwZone.StandardName, 
           TimeZoneInfo.ConvertTime(hwTime, hwZone, TimeZoneInfo.Local));
}
catch (TimeZoneNotFoundException)
{
   Console.WriteLine("The registry does not define the Hawaiian Standard Time zone.");
}                           
catch (InvalidTimeZoneException)
{
   Console.WriteLine("Registry data on the Hawaiian STandard Time zone has been corrupted.");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900