I'm not sure in which version of C# they got added, but you can now use format specifiers to format DateTime
objects like this:
var date = new DateTime(2021, 01, 01);
System.Console.WriteLine($"{date:MM.dd}"); // 01.01
Now I want to get the calendar week from a DateTime
object. Since ISO8601 specifies a slightly different week numbering than .Net
uses it, I need to provide custom logic to get the calendar week. The Problem I have now is not how to get the correct week numbers, since Microsoft provided a solution to that in their blog and there's also the ISOWeek
class, but rather: How I can add a custom format specifier like above so that I can do something like this?
var date = new DateTime(2021, 01, 01);
System.Console.WriteLine($"{date:WWW}"); // 53-2020
Is this even possible in C# 9? I'm guessing not since I've found very little on the topic so far.