NSDate Common methods
NSDate *date=[nsdate Date];//gets the current timeNSLog (@"%@", date);
NSDate*date1=[nsdate datewithtimeintervalsincenow:- -];//returns the current time as a benchmark, and then takes 60 seconds toNSLog (@"----%@", date1);
NSDate*date2=[nsdate dateWithTimeIntervalSince1970: +];//from 1970 onwards, after a number of secondsNSLog (@"%@", Date2);
NSDate*date3=[date2 Datebyaddingtimeinterval: -];//time is the standard plus a few secondsNSLog (@"%@", Date3);
Nstimeinterval Intervel=[date timeIntervalSince1970];//The number of seconds from 1970 to a certain time
NSLog (@ "%lf", intervel);
Nstimeinterval Intervel1=[date Timeintervalsincedate:date];//Count two time intervals (in seconds)
NSLog (@ "%lf", Intervel1);
Nstimeinterval intervel2=[Date1 Timeintervalsincenow]; NSLog (@"%LF", Intervel2);
NSDate*date4=[date Laterdate:date2];//get two more late (longer than 1970 months)NSLog (@"%@", date4);
NSDate *date=[NSDate Date];
//DateTime Formatted ObjectNSDateFormatter *formater=[[NSDateFormatter alloc]init];
//Set Date display format[Formater Setdateformat:@"YYYY--MM--DD HH:mm:ss"];//after formatting, the error does not exist. //Lowercase is a 12-hour, capital 24-hour system
//formatting datetime objects (converting date objects to strings)NSString *str=[formater Stringfromdate:date];//Replace a date with a string
NSLog (@"%@", str);
//Resolve Time DifferenceNSString *str=@"2015-11-3 10:20:00"; NSDateFormatter*foma=[[NSDateFormatter alloc]init]; [Foma Setdateformat:@"YYYY-MM-DD Hh:mm:ss"]; NSDate*date=[Foma Datefromstring:str]; //First Kind//and Greenwich, the differenceNsinteger timeoff=[[Nstimezone SYSTEMTIMEZONE]SECONDSFROMGMT]; //jet lag ConversionDate=[Date Datebyaddingtimeinterval:timeoff]; NSLog (@"%@", date);//The second Kind//set the time zone to UTC International calibration Time[Foma Settimezone:[nstimezone Timezonewithname:@"UTC"]]; NSDate*date1=[Foma Datefromstring:str]; NSLog (@"%@", date1); //Third Kind[Foma Settimezone:[nstimezone TIMEZONEFORSECONDSFROMGMT:0]]; NSDate*date1=[Foma Datefromstring:str]; NSLog (@"%@", date1);
Object-c NSDate