С# - Как вы показываете Apr'11 с DateTime.ToString

Хорошо. Я пробовал все, чтобы отобразить дату в формате Apr'11 с помощью метода DateTime ToString. В документации указано, что ' зарезервирован для строкового литерала, поэтому я бы подумал, что должен отображать один апостроф, который я использовал бы '''. Однако не нужно идти. Вот что я пробовал до сих пор:

taskdata.Month.Start.ToString("MMM 'yy")
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
taskdata.Month.Start.ToString("MMM ''yy")
"Apr 09"
taskdata.Month.Start.ToString("MMM '''yy")
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
taskdata.Month.Start.ToString("MMM ''''yy")
"Apr 09"
taskdata.Month.Start.ToString("MMM \'yy")
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
taskdata.Month.Start.ToString("MMM '\''yy")
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
Серьезно, какой секрет? Я отказываюсь конкатенировать!

Ответы

Ответ 1

Вам нужно сбежать (двойной побег, фактически):

new DateTime(2011, 10, 1).ToString("MMM \\'yy")

Ответ 2

String.Format(@"{0:MMM  \'yy}", DateTime.Now)

Работал для меня