NSString*dateStr = @"Wed May 222:27:08+0800 2012";
NSLocale* local =[[[NSLocale alloc]initWithLocaleIdentifier
[formatter setLocale: local];
4、自定義顯示的 星期 格式
使用NSDateFormatter轉換日期時,得到的英文字母的星期幾只能是這樣,如Sun, Mon, etc.
如果想得到大寫字母的星期幾,可以這樣:
5、計算距離某一天還有多少時間
NSDate* toDate
NSDate*
NSCalendar* chineseClendar = [ [ NSCalendar alloc ]initWithCalendarIdentifi
NSUInteger unitFlags =
NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit |NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit;
NSDateComponents *cps = [chineseClendar components:unitFlagsfromDate:startDate
NSInteger diffHour = [cps hour];
NSInteger diffMin
NSInteger diffSec
NSInteger diffDay
NSInteger diffMon
NSInteger diffYear = [cps year];
NSLog(
[toDate description], diffYear, diffMon, diffDay, diffHour,diffMin,diffSec );