Obtain the current date: nsdate * Date = [nsdate date]; // However, In this method, the UTC event is obtained.
Nsdate * Date = [nscalendardate date]; // obtain the local time.
Get the date of yesterday:
Nsdate * Yesterday = [[nscalendardate date] datebyaddinginternalinterval:-24*60*60];
Get the specified time:
Nsdate * nationaldate = [nsdate datewithstring: "00:00:00 + 0800"];
There is also a time string creation time object in the specified format:
Nsdateformatter * formatter = [[nsdateformatter alloc] init];
[Dateformatter setdateformat: @ "yyyy-mm-dd hh: mm: SS"];
[Dateformatter settimezone: @ "H"]; // H indicates + 0800. The corresponding I indicates + 0900. Z indicates-0100.
Nsdate * nationaldate2 = [formatter datefromstring: @ "00:00:00"];
The third method to use the string creation time is:
Nsdate * Date = [nscalendardate datewithstring: @ "4 Mar 2012" calendarformat: @ "% d % B % Y"]; // SPECIAL DATE formatting characters must be remembered.
Format the date into a string:
Nsdateformatter formatter = [[nsdateformatter alloc] init];
[Formatter setdateformat: @ "yyyy-mm-dd"];
[Formatter settimezone: @ "H"];
Nsstring * datestring = [formatter stringfromdate: date]; // 2012-03-04 will be output.
Nsdate * earlierdate = [yesterday earlierdate: Today]; // gets the date earlier than two dates. Yesterday is returned.
Nsdate * laterdate = [tomorrow laterdate: Today]; // get the date later than the two dates. Return tomorrow
Nscalendardate * cdate = [Today datewithcalendarformat: @ "% d % B % Y" timezone: [nstimezone localtimezone]; // convert the current date to the calendardate of the specified time zone based on the format string
Timeinternvalsincedate // This method is used to subtract two dates.