不能在NSDateFormatter中的年份之前放置单引号 [英] Can't put a single quote before the year in NSDateFormatter
问题描述
我要将日期格式设置如下:
I want to format my date as follows:
Mon, Apr 14 '09
dateFormat
我为我的 NSDateFormatter
是 EEE,MMM dd'yy
,但它显示:
The dateFormat
I'm setting for my NSDateFormatter
is EEE, MMM dd 'yy
but it shows:
Mon, Apr 14 'yy
如果我在一年前拿出单引号,我得到一年的最后两位数字,但不是很明显,这是一年,因为单引号已经走了。帮助?
If I take out the single quote before the year, I get the last two digits of the year but it's not obvious that it's the year because the single quote is gone. Help?
我也尝试过'''
,'\' '
和'\''''
之前'yy',但它不工作,虽然最后两个产生'yy
和''09
I've also tried putting '''
, '\''
, and '\'''
before 'yy' but it doesn't work, although the last two produced 'yy
and ''09
推荐答案
从 http://www.unicode.org/reports /tr35/tr35-31/tr35-dates.html#Date_Format_Patterns :
在模式中,两个单引号表示文字单引号,...
In patterns, two single quotes represents a literal single quote, …
在您的情况下:
[formatter setDateFormat:@"EEE, MMM dd ''yy"];
这篇关于不能在NSDateFormatter中的年份之前放置单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!