TimeZone localZone = TimeZone.CurrentTimeZone;BTW, Sysinternals' AD Explorer is great for finding out meta information (i.e. data type, property name) about AD attributes.
DateTime generalizedDate = DateTime.Parse(result.Properties["whenChanged"][0].ToString());
double hourDelta = localZone.IsDaylightSavingTime(generalizedDate) ? -4D : -5D;
DateTime lastUpdated = generalizedDate.AddHours(hourDelta);
Wednesday, April 13, 2011
Displaying ActiveDirectory's "whenChanged" attribute in C#
"whenChanged" comes through without the time offset. Not a big deal to fix it, but a quick Google search yielded no results on how to deal with it. Here's my solution to properly display Eastern Daylight/Standard time:
Subscribe to:
Post Comments (Atom)
1 comment:
Thank you for you post, that gives me hint and save me a lot of time!! :-)
here is my solution which can be using in any timezones:
DateTime utcTime = DateTime.Parse("30.10.2018 18:21:34")
DateTime localtime = ConvertUTCToLocalTime(utcTime);
public static DateTime ConvertUTCToLocalTime(DateTime UTCTime)
{
var localZone = TimeZone.CurrentTimeZone;
var offset = localZone.GetUtcOffset(UTCTime);
var localTime = UTCTime.AddHours(offset.Hours);
return localTime;
}
Post a Comment