tags:

views:

54

answers:

2

This is a quicky, what do I need to setup a different timzone in my application than that setup on IIS

All i want is to show a specific date in AESP rather than SPT, ist here a way in C# .NET 3.5?

+2  A: 

Try TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destTimeZone)

http://msdn.microsoft.com/en-us/library/bb382770.aspx

Matt
yes, but... the destimation timezone, i dont want it to always be Standard time, i want it to automatically adjust to daylight savings as well, convertime is pretty fixed
Ayyash
@Ayyash: No, ConvertTime will take account of daylight savings as well.
Jon Skeet
actualyl you're right it does, what i am looking for is to display the time zone identified or display name correctly, by retreiving the IsDaylightSavingTime property, but how? how do i retreive whether it is daylight saving in a completly different time zone?
Ayyash
You can't identify a time zone that way. There can be many different time zones all with the same standard offset and DST offset. However, detecting DST in a different time zone is easy: TimeZoneInfo.IsDaylightSavingTime.
Jon Skeet
A: 

I figured it out:

DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
dtfi.FullDateTimePattern = "yyyy-MM-ddTHH:mmzzz";
DateTime s = DateTime.Parse(inputstring, dtfi);
s = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(s, "AUS Eastern Standard Time");
TimeZoneInfo tzz = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
string timezone = (tzz.IsDaylightSavingTime(s)) ? tzz.DaylightName : tzz.StandardName;

CultureInfo  culture = CultureInfo.CreateSpecificCulture("en-AU");
string output = String.Format("{0} | {1}", s.ToString("f", culture), timezone);

so input is: 2009-10-13T10:00-7:00
output is: Wednesday, 14 October 2009 4:00 AM | AUS Eastern Daylight Time

input is: 2009-9-13T10:00-7:00
output is: Monday, 14 September 2009 3:00 AM | AUS Eastern Standard Time

Ayyash