Microsoft.SharePoint.WebControls.DateTimeControl ignores regional settings

When you use an instance of the Microsoft.SharePoint.WebControls.DateTimeControl in SharePoint (for example in a webpart), the locale will always be set to en-US, even if the web of user have specified a different locale.

To overcome this, you need to explicitly set the LocaleId property of the control to the correct locale.

DateTimeControl dtCtrl =new DateTimeControl();
dtCtrl.ID = "dtCtrl";
dtCtrl.LocaleId = (int)SPContext.Current.RegionalSettings.LocaleId;
this.Controls.Add(dtCtrl);

You should use SPContext.Current.RegionalSettings as this reflects the RegionalSettings for the current user (they might differ from the Web if the user modified this).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>