Hi,
We recently had a requirement wherein we were working with DateTime fields in a Plugin. It was related to Time Zone.
These articles were of extreme help.
http://develop1.net/public/post/Dynamics-CRM-DateTimes-the-last-word.aspx
http://inogic.com/blog/2015/06/handling-datetime-fields-in-microsoft-dynamics-crm-update-1/
http://ttidbit.blogspot.com/2013/01/crm-timezone-codes.html
Sample Code to use LocalTimeFromUtcTimeRequest
var currentUserSettings = organizationProxy.RetrieveMultiple( new QueryExpression("usersettings") { ColumnSet = new ColumnSet("timezonecode"), Criteria = new FilterExpression { Conditions = { new ConditionExpression("systemuserid", ConditionOperator.EqualUserId) } } }).Entities[0]; var timeZoneCode = currentUserSettings.Attributes["timezonecode"].ToString(); DateTime time1 = DateTime.UtcNow; LocalTimeFromUtcTimeRequest convert = new LocalTimeFromUtcTimeRequest(); convert.UtcTime = time1.ToUniversalTime(); convert.TimeZoneCode = Convert.ToInt32(timeZoneCode); LocalTimeFromUtcTimeResponse response = (LocalTimeFromUtcTimeResponse)organizationProxy.Execute(convert); MessageBox.Show(response.LocalTime.ToString());
The interesting part was that our plugin was running under the context of System account, so to get the logged in user from UI, we added an additional field and populated the value of time zone in it on on load using current logged in user’s information, and used the same field in plugin.
Hope it helps..