Skip to content

Culture en-CH is different in WASM from server values #120898

@alexaka1

Description

@alexaka1

Description

If I use en-CH in my Blazor Web App, dates are formatted differently on the server and in the client.

I noticed that the CultureInfo.DateTimeFormat is substantially different in WASM from the server.

The following diff takes the server as base, and indicates wasm deviations:
{
- "AMDesignator": "AM",
+ "AMDesignator": "am",
  "Calendar": {
    "MinSupportedDateTime": "0001-01-01T00:00:00",
    "MaxSupportedDateTime": "9999-12-31T23:59:59.9999999",
    "AlgorithmType": 1,
    "IsReadOnly": true,
    "Eras": [
      1
    ],
    "TwoDigitYearMax": 2049
  },
- "DateSeparator": ".",
+ "DateSeparator": "/",
  "FirstDayOfWeek": 1,
  "CalendarWeekRule": 2,
  "FullDateTimePattern": "dddd, d MMMM yyyy HH:mm:ss",
  "LongDatePattern": "dddd, d MMMM yyyy",
  "LongTimePattern": "HH:mm:ss",
  "MonthDayPattern": "d MMMM",
-  "PMDesignator": "PM",
+  "PMDesignator": "pm",
  "RFC1123Pattern": "ddd, dd MMM yyyy HH\u0027:\u0027mm\u0027:\u0027ss \u0027GMT\u0027",
- "ShortDatePattern": "dd.MM.yyyy",
+ "ShortDatePattern": "dd/MM/yyyy",
  "ShortTimePattern": "HH:mm",
  "SortableDateTimePattern": "yyyy\u0027-\u0027MM\u0027-\u0027dd\u0027T\u0027HH\u0027:\u0027mm\u0027:\u0027ss",
  "TimeSeparator": ":",
  "UniversalSortableDateTimePattern": "yyyy\u0027-\u0027MM\u0027-\u0027dd HH\u0027:\u0027mm\u0027:\u0027ss\u0027Z\u0027",
  "YearMonthPattern": "MMMM yyyy",
  "AbbreviatedDayNames": [
    "Sun",
    "Mon",
    "Tue",
    "Wed",
    "Thu",
    "Fri",
    "Sat"
  ],
  "ShortestDayNames": [
    "Su",
    "Mo",
    "Tu",
    "We",
    "Th",
    "Fr",
    "Sa"
  ],
  "DayNames": [
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday"
  ],
  "AbbreviatedMonthNames": [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec",
    ""
  ],
  "MonthNames": [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December",
    ""
  ],
  "IsReadOnly": true,
- "NativeCalendarName": "Gregorian Calendar",
+ "NativeCalendarName": "gregorian",
  "AbbreviatedMonthGenitiveNames": [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec",
    ""
  ],
  "MonthGenitiveNames": [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December",
    ""
  ]
}

Am I missing something here? I was very surprised that they are different, I would not expect that at all.

Reproduction Steps

Follow this guide to enable globalization in wasm: https://learn.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-9.0#dynamically-set-the-culture-in-a-blazor-web-app-by-user-preference

Create 2 components, one with interactive server and the other with interactive webassembly with roughly the following:

@{
    var culture = CultureInfo.GetCultureInfo("en-CH");
}
<span>@DateTime.Now.ToString("G", culture)</span>

Expected behavior

Date is formatted as the following 18.10.2025 13:30:00 in all render modes.

Actual behavior

Date is formatted as 18.10.2025 13:30:00 on the server (static, interactiveserver).
Date is formatted as 18/10/2025 13:30:00 on the client (interactivewebassembly).

Regression?

No response

Known Workarounds

Patch the culture before setting the app's culture. I.e:

if (culture.IetfLanguageTag is "en-CH")
{
    culture = new CultureInfo(culture.IetfLanguageTag)
   {
       DateTimeFormat =
       {
           DateSeparator = ".",
           ShortDatePattern = "dd.MM.yyyy",
       },
   };
}

Configuration

.NET 9 SDK 9.0.306

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions