(NSString *) = = Thu OCT 16 17:06:25 +0800 2014
//DateFormat = EEE MMM dd HH:mm:ss Z yyyy
nsdateformatter *fmt = [[nsdateformatteralloc] init ];
// If it is a real machine debug, convert this European and American time, you need to set locale
Fmt.locale = [[Nslocale alloc] initwithlocaleidentifier:@ "en_US"];
Fmt.locale = [[Nslocale alloc] initwithlocaleidentifier:@ "ZH_CN"];
//E: Day of the week
//M: Month
//d: What date ( the day of the month )
// hour of h:24 hours
//m: min
//s: sec
//Z: time zone
//y: Year
// Set Date format ( the meaning of each number and word inside the declaration string )
FMT. DateFormat = @ "EEE MMM dd HH:mm:ss Z yyyy" ;
nsdate *createdate = [FMT datefromstring:(NSString *)]; // turn (NSString *) into a Time object
//Fmt.dateformat = @ "Yyyy-mm-dd HH:mm:ss";// This format
//(NSString *) = [FMT stringfromdate:createdate];// Convert the time object to a string of this format
// Current time
nsdate *now = [nsdatedate];
// Calendar Object ( easy to compare the gap between two dates )
nscalendar *calendar = [nscalendarcurrentcalendar];
/*
Nscalendarunitera = Kcfcalendarunitera,
Nscalendarunityear = Kcfcalendarunityear,
Nscalendarunitmonth = Kcfcalendarunitmonth,
Nscalendarunitday = Kcfcalendarunitday,
Nscalendarunithour = Kcfcalendarunithour,
Nscalendarunitminute = Kcfcalendarunitminute,
Nscalendarunitsecond = Kcfcalendarunitsecond,
Nscalendarunitweekday = Kcfcalendarunitweekday,
Nscalendarunitweekdayordinal = Kcfcalendarunitweekdayordinal,
*/
the //Nscalendarcalendarunit enumeration represents what difference you want to get
nscalendarunit unit = kcfcalendarunityear | Kcfcalendarunitmonth | Kcfcalendarunitday | Kcfcalendarunithour | Kcfcalendarunitminute | Kcfcalendarunitsecond ;
// calculate a time difference between two dates
nsdatecomponents *cmps = [Calendar Components: unit FromDate: createdate toDate : Now options: 0];
NSLog(@ "%@---%@---%@", CreateDate, now, cmps);
IOS Date Related Summary