-
Notifications
You must be signed in to change notification settings - Fork 6k
Open
Labels
dotnet-fundamentals/svcokr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Description
Type of issue
Code doesn't work
Description
In "How to: Display milliseconds in date and time values", the example inserts a milliseconds format specifier into the format string by searching for the "(:ss|:s)" regular expression in DateTimeFormatInfo.FullDateTimePattern:
Lines 24 to 30 in 0dd37de
string fullPattern = DateTimeFormatInfo.CurrentInfo.FullDateTimePattern; | |
// Create a format similar to .fff but based on the current culture. | |
string millisecondFormat = $"{NumberFormatInfo.CurrentInfo.NumberDecimalSeparator}fff"; | |
// Append millisecond pattern to current culture's full date time pattern. | |
fullPattern = Regex.Replace(fullPattern, "(:ss|:s)", $"$1{millisecondFormat}"); |
In some cultures however, DateTimeFormatInfo.FullDateTimePattern does not contain any colons and the regex thus won't match. The sample code won't display any milliseconds in those cultures. With .NET 8.0.1 on Windows, those cultures are:
Name | EnglishName | FullDateTimePattern | LongTimePattern |
---|---|---|---|
as-IN | Assamese (India) | dddd, d MMMM, yyyy tt h.mm.ss | tt h.mm.ss |
da-DK | Danish (Denmark) | dddd 'den' d. MMMM yyyy HH.mm.ss | HH.mm.ss |
da-GL | Danish (Greenland) | dddd 'den' d. MMMM yyyy HH.mm.ss | HH.mm.ss |
en-DK | English (Denmark) | dddd, d MMMM yyyy HH.mm.ss | HH.mm.ss |
en-FI | English (Finland) | dddd, d MMMM yyyy H.mm.ss | H.mm.ss |
fi-FI | Finnish (Finland) | dddd d. MMMM yyyy H.mm.ss | H.mm.ss |
fr-CA | French (Canada) | dddd d MMMM yyyy HH 'h' mm 'min' ss 's' | HH 'h' mm 'min' ss 's' |
id-ID | Indonesian (Indonesia) | dddd, dd MMMM yyyy HH.mm.ss | HH.mm.ss |
kl-GL | Kalaallisut (Greenland) | yyyy MMMM d, dddd HH.mm.ss | HH.mm.ss |
si-LK | Sinhala (Sri Lanka) | yyyy MMMM d, dddd HH.mm.ss | HH.mm.ss |
smn-FI | Inari Sami (Finland) | dddd, MMMM d. yyyy H.mm.ss | H.mm.ss |
This caused bug dotnet/aspire#3127 in the .NET Aspire dashboard.
Please correct the example so that it detects the seconds format specifier in these cultures too.
Page URL
Content source URL
Document Version Independent Id
80f9e353-0de8-c715-233e-033e6dd3c375
Article author
Metadata
- ID: 2691d246-9d0a-5714-a3a3-19aabfb3c5cd
- Service: dotnet-fundamentals
Metadata
Metadata
Assignees
Labels
dotnet-fundamentals/svcokr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.