Extension of the class
NSDate is the base class for processing dates and times in cocoa, encapsulating a given moment, specific datetime, and time zone
Use the +date method to get the current date and time
1NSDate *date = [NSDate Date];//Get current Time2NSLog (@"%@", date);//No matter what time zone you are in, the time to print is always o timezone3NSDate *date2 = [NSDate datewithtimeintervalsincenow: -* -*8];//the time from now onwards4NSLog (@"%@", date2);5Nstimeinterval date3 = [date timeIntervalSince1970];//Get time interval from 1970 to present6NSLog (@"%f", Date3);
Nstimeinterval
The double type that represents the time interval in seconds
You can use the-initwithtimeintervalsincenow:? method to pass in a nstimeinterval parameter, create a NSDate object
For example: nsdate * tomorrowdate = [[NSDate alloc] initwithtimeintervalsincenow:24*60 * 60];
NSDate * yesterdaydate = [[NSDate alloc] initwithtimeintervalsincenow:-1 * 24*60 *60];
Interval of two time objects: Nstimeinterval = [Tomorrowdate timeintervalsincedate:yesterdaydate];
1NSDateFormatter *format =[[NSDateFormatter alloc] init];2[Format Setdateformat:@"YYYY-MM-DD HH:mm:ss"];3 //YYYY represents a 4-digit year4 //mm stands for two-bit months5 //DD stands for two-bit day6 //HH stands for 24 Hours of input7 //mm stands for two-bit minutes8 //SS stands for two-bit seconds9 //nsdateformatter function is nsstring and nsdateTen //1.NSDate conversion to NSString OneNSString *datestr =[format stringfromdate:date]; ANSLog (@"%@", datestr); - -NSDate *newdate = [format datefromstring:@"2014-07-02 11:54:03"]; theNSLog (@"%@", newdate);