[CLOSED] TimeField am/pm in en-US culture

  1. #1

    [CLOSED] TimeField am/pm in en-US culture

    Hi,
    I have multilanguage application, and I have a small problem with TimeField am/pm in en-US culture.
    If the culture is en-GB or fr-FR, I get 14:14:00 in server side; but if the cultutre is en-US, I get 2:14 pm
    And if I use TimeFrom as a parameter in TestTimeField action, I get error null for this parameter.
    Can you tell me how I can work around with this problem?

    Here is the test case:
    @using System.Globalization
    @using System.Threading
    @model TimeSpan
    
    @{
        Layout = null;
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    }
     @(Html.X().ResourceManager())
    @(Html.X().FormPanel().ID("MyForm").Layout(LayoutType.Form).Title("Test Form")
          .Items(Html.X().TimeField().FieldLabel("Test TimeField").Value(Model)
                     .Format("HH:mm").ID("TimeFrom"))
          .Buttons(Html.X().Button()
                       .Text("Click Me")
                       .DirectEvents(d =>
                           {
                               d.Click.Url = Url.Action("TestTimeField");
                               d.Click.FormID = "MyForm";
                           })))
    public ActionResult Index()
            {
                var model = new TimeSpan(14, 14, 14);
                return View(model);
            }
    
            public ActionResult TestTimeField(FormCollection values)
            {
                string TimeFrom = values["TimeFrom"];
                return new DirectResult(TimeFrom);
            }
    Last edited by Daniil; Sep 25, 2013 at 8:25 AM. Reason: [CLOSED]
  2. #2
    Hi @UnifyEducation,

    In your scenario a TimeField's time is submitted in its SubmitFormat.
    http://docs.sencha.com/extjs/4.2.1/#...g-submitFormat

    By default, it is "t" in .NET date time format string. I.e. it is Short Time format specifier.
    http://msdn.microsoft.com/en-us/libr...aspx#ShortTime

    So, it is different across the en-GB, fr-FR and en-US locales. You can specify some specific SubmitFormat regardless the locale.

    If you don't change the default SubmitFormat, then the following approach should work regardless the locale.
    public ActionResult TestTimeField(FormCollection values)
    {
        TimeSpan time = X.GetCmp<TimeField>("TimeFrom").SelectedTime;
        return new DirectResult();
    }
    And if I use TimeFrom as a parameter in TestTimeField action, I get error null for this parameter.
    Do you use this parameter in the action's signature?
    TimeSpan TimeFrom
  3. #3
    Thank you for your answer. You can close this thread.
    If I use this parameter in the action's signature, so I must do like this:

    public ActionResult TestTimeField(DateTime TimeFrom)
            {
                var value = TimeFrom.TimeOfDay;
                return new DirectResult(value );
            }

Similar Threads

  1. [CLOSED] New Culture Resources
    By softmachine2011 in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: May 04, 2012, 2:02 PM
  2. Culture name 'da-da' is not supported.
    By plykkegaard in forum Bugs
    Replies: 9
    Last Post: Jun 20, 2011, 6:52 AM
  3. Replies: 4
    Last Post: Apr 15, 2011, 3:53 PM
  4. TimeField and en-US culture problem
    By Ealirene in forum 1.x Help
    Replies: 1
    Last Post: Mar 21, 2011, 8:00 AM
  5. Date format/culture
    By MrMp3 in forum 1.x Help
    Replies: 2
    Last Post: Mar 19, 2008, 10:26 AM

Posting Permissions