Often times, you will have custom web parts or code that write date values back to lists. In many cases, time zone settings are different across an organization and using DateTime.Now is generally not recommended.
Two scenarios come to mind. #1, when a site changes its time zone to be different than the hosted servers’ time zone. #2, if a web part was deployed across a Site Collection and used in 5 different sub-sites with 5 different regional time zone settings.
I found the best way to retrieve a date is this here:
// time zone of site
SPTimeZone siteTimeZone = SPContext.Current.Web.RegionalSettings.TimeZone;
// currentTime will contain the current date and time according to the sites’ time zone settings
DateTime currentTime = siteTimeZone.UTCToLocalTime(DateTime.Now.ToUniversalTime());
This will give you the current time in relation to the Site Regional Settings and will account for changes to the settings.
Leave A Comment