Home

Sep 21, 2010

Change the default SelectedDateFormat of Silverlight DateTime Picker

Silverlight dateTime picker displays regional setting dateTime format in datePicker. In order to change this you need to modify the local computer culture using below code :

     public MainPage()
     {
         InitializeComponent();
         //force dates to always be MM/dd/yyyy regardless of culture
       
Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
         Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
         Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern = "h:mm tt";
     }

Regards,
Amol

No comments: