Keeping datetime culture invariant

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • helveticus

    Keeping datetime culture invariant

    Is there a way to keep datetime expressions culture invariant? My app
    is culture dependent and contains a series of datetime settings that
    are saved in cookies. The cookie date strings raise exceptions when
    they are read back since they won't be recognized in certain cultures
    (ie US MM/DD/YY vs EU DD.MM.YY)? Currently, I track the culture state,
    but this is cumbersome.

    Is there a simple way to force the run-time to keep all dates in a
    single format regardless of the culture state? I would like to avoid
    erasing all cookies on culture change.

    TIA for any hints. (ASP.NET 3.5)
  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: Keeping datetime culture invariant

    helveticus wrote:
    Is there a way to keep datetime expressions culture invariant? My app
    is culture dependent and contains a series of datetime settings that
    are saved in cookies. The cookie date strings raise exceptions when
    they are read back since they won't be recognized in certain cultures
    (ie US MM/DD/YY vs EU DD.MM.YY)? Currently, I track the culture state,
    but this is cumbersome.
    >
    Is there a simple way to force the run-time to keep all dates in a
    single format regardless of the culture state? I would like to avoid
    erasing all cookies on culture change.
    >
    TIA for any hints. (ASP.NET 3.5)
    I recommend keeping to the ISO 8601 standard for culture independent
    dates. It's unambiguos, so there is minimal risk that it's misunderstood.

    Use the string "yyyy-MM-dd" to format and parse dates:

    string formatted = someDateTime.To String("yyyy-MM-dd");

    DateTime parsed = DateTime.ParseE xact(someString , "yyyy-MM-dd",
    CultureInfo.Inv ariantCulture);

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • helveticus

      #3
      Re: Keeping datetime culture invariant

      Thanks! Completely forgot about the .InvariantCultu re property.

      Comment

      Working...