Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
125
Text property not including AM PM
posted

We have an install on a single computer that is reading the time from the webdatetime editor control differently than our other installs. It is on a Canadian French computer, and when I read the .Text property of the field it does not include the AM/PM that is shown in the text field. Another oddity is that it won't show PM just AM (you can try and switch but it switches right back as far as I can tell). We have a number of other controls that seem to be working fine (webdate picker, webdatatree, webdatagrid). I won't be able to give anything that reproduces this as it's only on their install. I have tried setting the date format for display and edit mode of the controls via System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat but that still does not help, and seems to set for 24 hour format but you can only enter in hours 1-12. Is there anything I can set/change that could fix this issue?

Example: Editor text area shows: 12:00:00 AM, during postback the .Text property shows: 12:00:00

  • 10685
    Offline posted

    Hello,

     

    Thank you for posting in our community.

    From what I understand, the issue is a lack of AM, PM when using fr-CA culture. WebDateTime editor is based on the official culture and date/time formats implemented by Microsoft.

    I have investigated the matter for you, and it appears it is the expected culture specific behavior, based on the following MSDN resource , and in particular:

     

    DateTime date1 = new DateTime(2008, 4, 10, 6, 30, 0);
    Console.WriteLine(date1.ToString("f", CultureInfo.CreateSpecificCulture("en-US")));
    // Displays Thursday, April 10, 2008 6:30 AM                       

    Console.WriteLine(date1.ToString("f", CultureInfo.CreateSpecificCulture("fr-FR")));

    // Displays jeudi 10 avril 2008 06:30 

     

    f - Full date/time pattern (short time).

    Full date/time pattern (short time).

    More information: The Full Date Short Time ("f") Format Specifier.

    2009-06-15T13:45:30 -> Monday, June 15, 2009 1:45 PM (en-US)

    2009-06-15T13:45:30 -> den 15 juni 2009 13:45 (sv-SE)

    2009-06-15T13:45:30 -> Δευτέρα, 15 Ιουνίου 2009 1:45 μμ (el-GR)

     

    Based on these, I suggest each Specific Culture determines if the AM, PM portion should be show or not in the predefined date/time patters. 

    In case you would like to set this portion to be always visible and use custom patter, you can use tt at the end of the pattern.

    PMDesignator Property -

     If the custom pattern includes the format pattern "tt" and the time is after noon,  DateTime.ToString  displays the value of PMDesignator in place of the "tt" in the format pattern. If the custom pattern includes the format pattern "t", only the first character of PMDesignator is displayed. Your application should use "tt" for languages for which it is necessary to maintain the distinction between AM and PM.

    For example, the following output / 28-09-2010 11:56  AM / is based on : 

                  WebDateTimeEditor4.Culture = new System.Globalization.CultureInfo("fr-CA"); 

                  <ig:WebDateTimeEditor ID="WebDateTimeEditor4" runat="server" Width="300px"

                         DisplayModeFormat="dd/MM/yyyy HH:mm tt"

                         EditModeFormat="dd/MM/yyyy HH:mm  tt"

                         Fields="2010-9-28-16-59-0-0">
                  </ig:WebDateTimeEditor>

     

    However, the text property will return the text based on the Specific Culture Set, disregarding the tt portion AM/PM.
    What is more, it will allow you to enter 24h based input and AM/PM I correctly updated.I am attaching a code sample you can refer to. Please let me know in case you have any questions or concerns regarding this matter.

    DTE_CanadianFrench_AMPM.zip