您的位置:首页 > 其它

NSDateFormatter的格式字符串

2011-02-11 14:58 375 查看
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateStyle:NSDateFormatterMediumStyle];

[dateFormatter setTimeStyle:NSDateFormatterShortStyle];

//[dateFormatter setDateFormat:@"hh:mm:ss"]

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"
];
//毫秒

NSLog(@"Date%@"
, [dateFormatter stringFromDate:[NSDate date]]);

[dateFormatter release];

Specifier

Description

%%


A
'%'

character

%a


Abbreviated weekday name

%A


Full weekday name

%b


Abbreviated month name

%B


Full month name

%c


Shorthand for “
%X %x

", the locale format for date and time

%d


Day of the month as a decimal number (01-31)

%e


Same as
%d

but does not print the leading 0 for days 1 through 9 (unlike
strftime()

, does not print a leading space)

%F


Milliseconds as a decimal number (000-999)

%H


Hour based on a 24-hour clock as a decimal number (00-23)

%I


Hour based on a 12-hour clock as a decimal number (01-12)

%j


Day of the year as a decimal number (001-366)

%m


Month as a decimal number (01-12)

%M


Minute as a decimal number (00-59)

%p


AM/PM designation for the locale

%S


Second as a decimal number (00-59)

%w


Weekday as a decimal number (0-6), where Sunday is 0

%x


Date using the date representation for the locale, including the time zone (produces different results from
strftime()

)

%X


Time using the time representation for the locale (produces different results from
strftime()

)

%y


Year without century (00-99)

%Y


Year with century (such as 1990)

%Z


Time zone name (such as Pacific Daylight Time; produces different results from
strftime()

)

%z


Time zone offset in hours and minutes from GMT (HHMM)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: