xexexe

NSDateFormatterStyle 几种取值的区别

将NSDate对象转换成字符串的地方很多,其中不免会使用到NSDateFormatterStyle。今天对NSDateFormatterStyle的值进行测试,看看有什么效果,废话不多说,看代码:
取值范围:

1
2
3
4
5
6
7
8
typedef NS_ENUM(NSUInteger, NSDateFormatterStyle) {
// date and time format styles
NSDateFormatterNoStyle = kCFDateFormatterNoStyle,
NSDateFormatterShortStyle = kCFDateFormatterShortStyle,
NSDateFormatterMediumStyle = kCFDateFormatterMediumStyle,
NSDateFormatterLongStyle = kCFDateFormatterLongStyle,
NSDateFormatterFullStyle = kCFDateFormatterFullStyle
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
- (NSDateFormatter *)dateFormatter
{
static NSDateFormatter *dateFormatter;
if (!dateFormatter) {
dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter = [[NSDateFormatter alloc] init];
// NSDateFormatterStyle几种取值样式
// NSDateFormatterNoStyle
// 例如: (其实就是空白的,不显示)
// NSDateFormatterShortStyle
// 例如:下午7:00 | 15/5/19
// NSDateFormatterMediumStyle
// 例如:下午7:00:00 | 2013年5月19日
// NSDateFormatterLongStyle
// 例如:GMT +8下午7:00:00 | 2013年5月19日
// NSDateFormatterFullStyle
// 例如:中国标准时间下午7:00:00 | 2013年5月19日 星期日
dateFormatter.timeStyle = NSDateFormatterFullStyle;
dateFormatter.dateStyle = NSDateFormatterLongStyle;
}
return dateFormatter;
}