Two nsdate can be compared between the two.
It's easy to compare two dates with Nscalendar.
/**
1. This year
1> today
* 1: Just
* 1 min ~59: xx minutes ago
* More than 60 minutes: xx hours ago
2> yesterday
* Yesterday xx:xx
3> Other
* Xx-xx xx:xx
2. Not this year
1> xxxx-xx-xx xx:xx
*/
-(NSString *) created_at
{
_created_at = = Thu OCT 16 17:06:25 +0800 2014
DateFormat = = EEE MMM dd HH:mm:ss Z yyyy
NSString-NSDate
NSDateFormatter *fmt = [[NSDateFormatter alloc] 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"];
Format the date (the meaning of each number and word inside the declaration string)
E: Day of the week
M: Month
D: What date (the day of the month)
H: 24-hour hour
M: minutes
S: sec
Y: Year
Fmt.dateformat = @ "EEE MMM dd HH:mm:ss Z yyyy";
Date of creation of Weibo
NSDate *createdate = [FMT datefromstring:_created_at];
Current time
NSDate *now = [NSDate Date];
Calendar object (easy to compare the gap between two dates)
Nscalendar *calendar = [Nscalendar Currentcalendar];
Nscalendarunit enumeration represents what difference you want to get
Nscalendarunit unit = Nscalendarunityear | Nscalendarunitmonth | Nscalendarunitday | Nscalendarunithour | Nscalendarunitminute | Nscalendarunitsecond;
Calculates the difference between two dates
nsdatecomponents *cmps = [Calendar components:unit fromdate:createdate Todate:now options:0];
Hwlog (@ "%@%@%@", CreateDate, now, cmps);
return _created_at;
}
1016-09-Home 22-date Conversion