Odd military time issue

4 posts, 0 answers
  1. Tyler
    Tyler avatar
    15 posts
    Member since:
    Dec 2010

    Posted 10 May 2011 Link to this post

    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;
                    }
                }
            }
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 12 May 2011 Link to this post

    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
  3. DevCraft banner
  4. Steve
    Steve avatar
    19 posts
    Member since:
    Apr 2009

    Posted 10 Nov 2011 Link to this post

    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;
  5. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 14 Nov 2011 Link to this post

    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 >>

Back to Top