I'm displaying localized short dates by providing culture info to DateTime.ToString
method. By now I was using
x.ToString("d", ci); // 23.12.2000
that displays short date. But now I would like to also include abbreviated day name. I tried
x.ToString("ddd d", ci); // pon 23
but now d
becomes day specifier instead of short date format so instead of day name and short date I only get day name and day number.
How do I convince formatter to display day along with predefined culture short date format?
How about:
string.Format(ci, "{0:ddd} {0:d}", x)
The "standard" formatting strings work by obtaining the equivalent property of the CultureInfo
's DateTimeFormat
. In this case "d"
finds the ShortDatePattern
property, which will be something like "dd.MM.yyyy", "dd/MM/yyyy", "MM/dd/yyyy", "yyyy-MM-dd" and so on, depending on that locale in question.
Hence you can make use of it in a custom pattern like so:
x.ToString("ddd " + ci.DateTimeFormat.ShortDatePattern, ci) // Sat 2000-12-23 on my set up, should presumably be pon 23.12.2000 on yours
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With