[英]C# - How do you display Apr '11 with DateTime.ToString
Ok I've tried everything to render a date in the Apr '11 format with the DateTime ToString
method.好的,我已经尝试了所有使用
DateTime ToString
方法以Apr '11格式呈现日期的方法。 The documentation says '
is reserved for a string literal, so I would think to display a single apostrophe I'd use '''
- However, no go.文档说
'
是为字符串文字保留的,所以我想显示一个我会使用'''
撇号'''
- 但是,不行。 Here's what I've tried so far:这是我迄今为止尝试过的:
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
Seriously what's the secret?说真的,秘密是什么? I refuse to concatenate!
我拒绝串联!
你需要逃脱(实际上是双重逃脱):
new DateTime(2011, 10, 1).ToString("MMM \\'yy")
String.Format(@"{0:MMM \'yy}", DateTime.Now)
为我工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.