This is a migrated thread and some comments may be shown as answers.

Odd military time issue

3 Answers 80 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 10 May 2011, 03:28 PM
My customers are use to always using military time. The RadDateTimePicker handles PM values like 1405 (2:05 PM), however, if a user enters something like 5/10/2011 0105, it will convert it to 10:05 am instead of 1:05 am. Is there a way to fix this?

I found a temporary solution, but it is not very clean. I added the ParseDateTimeValue event to my controls...
private void RadDateTimePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
        {
            if(args.IsParsingSuccessful)
            {
                string textToParce = args.TextToParse.Trim();
                DateTime parced;
                while (textToParce.Contains(" 0"))
                {
                    textToParce = textToParce.Replace(" 0", " ");
                }
                for (int i = 1; i < 10;i++ )
                {
                    if (textToParce.Contains(" " + i))
                    {
                        textToParce = textToParce.Replace(" " + i, " " + i + ":");
                        i = 10;
                    }
                }
                if(DateTime.TryParse(textToParce,out parced))
                {
                    args.Result = parced;
                }
            }
        }

3 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 12 May 2011, 11:14 AM
Hi Tyler,

 Currently this is the only way to customize the parsing of date/time in the RadDateTimePicker control - using the ParseDateTimeValue event of the RadDateTimePicker control.

Kind regards,
Miroslav Nedyalkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Steve
Top achievements
Rank 1
answered on 10 Nov 2011, 09:35 PM
Change the applications culture to use military time so that all date/time use from here on (grids, datetimepicker, etc) will be in military time.
// Change the default date/time format so that all subsequent displays of date/time will use these formats.
CultureInfo cultureInfo = new CultureInfo("en-US")
   {
      DateTimeFormat = new DateTimeFormatInfo
         {
            ShortDatePattern = "dd-MMM-yyyy",
            ShortTimePattern = "HHmm",
            LongTimePattern = "HHmm"
         }
   };
 
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
0
Miroslav Nedyalkov
Telerik team
answered on 14 Nov 2011, 10:02 AM
Hi Steve,

Thank you very much for your suggestion! It works find and sounds like the preferred way to allow input of military time format. Your Telerik points were updated for your cooperation.

All the best,
Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
DateTimePicker
Asked by
Tyler
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Steve
Top achievements
Rank 1
Share this question
or