When i display my system date using DateTime.Now()
function It gives me system date and time and works fine but when i try to run this page on my server
it gives me the DateTime of Server which is outside India But i want to pick up the time of India whenever this page is executed on server.
I know it is possible through Culture Info
Class... Any suggestion....
views:
44answers:
1
+2
A:
Put:
private static TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
as a field.
Then, use:
DateTime indianTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);
to get the time as needed.
Matthew Flaschen
2010-07-16 05:09:58
@Mathew `Cannot implicitly convert type 'System.TimeZoneInfo' to 'System.DateTime`
Pandiya Chendur
2010-07-16 05:17:44
@mathew `The best overloaded method match for 'System.TimeZoneInfo.ConvertTimeFromUtc(System.DateTime, System.TimeZoneInfo)' has some invalid arguments`
Pandiya Chendur
2010-07-16 05:18:24
@Pandiya: Put `TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Indian Standard Time");` and then `DateTime indianTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow,tzi);`
KMan
2010-07-16 05:21:45
@KMan `The time zone ID 'Indian Standard Time' was not found on the local computer.`
Pandiya Chendur
2010-07-16 05:23:27
@Pandiya: Apologies for the typo, try "India Standard Time". Just tested it.
KMan
2010-07-16 05:29:18
Sorry for my typos. Another source had indicated that "Indian Standard Time" was correct.
Matthew Flaschen
2010-07-16 05:33:53