Question

I have a question, basically i have a date time which is by default in UTC, how do i programmatically convert it to a correct date time in regional settings of the site collection / or user?

Was it helpful?

Solution

For full explanation see Dealing with Multiple Time Zones in SharePoint 2010

var user = SPContext.Current.Web.CurrentUser;
// Always perform a Null-Check on SPUser.RegionalSettings
if (user.RegionalSettings != null)
{
    return user.RegionalSettings.TimeZone.UTCToLocalTime(listDateUtc);
}
else
{
    // User didn't set a time zone, so use the one from the Web
    return SPContext.Current.Web.RegionalSettings.TimeZone.UTCToLocalTime(listDateUtc);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top