1. Show Current Time
NSDate *date = [nsdate date]; gets the current time
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[Formatter setdateformat:@ "Yyyy-mm-dd a HH:mm:ss eeee"];
NSLog (@ "date =%@", [formatter stringfromdate:date]);
//output result is date = 2015-10-09 pm 20:34:05 Friday
// Get the time of yesterday
nsdate *dateofyesterday = [nsdate datewithtimeinterval:- *3600 sincedate:d ate];
NSLog(@ "yesterday =%@", [Formatter stringfromdate:d ateofyesterday]);
// output yesterday = 2015-10-08 pm 20:55:28 Thursday
//2. Displays the number of seconds in the common time format
nsdate *dates = [nsdate dateWithTimeIntervalSince1970:+];
nsdateformatter *formatters = [[nsdateformatter alloc]init ];
[formatters setdateformat:@ "Mm:ss"];
NSLog(@ "100s =%@", [formatters stringfromdate:d ates]);
// output is 100s = 01:40
3. customizing the regional language
Formatter. Locale = [nslocale localewithlocaleidentifier:@ "en_US"];//Celestial is ZH_CN
NSLog(@ "data =%@", [Formatter stringfromdate:d ate]);
// output data = 2015-10-09 PM 20:43:11 Friday
4. convert string to bit nsdate type
nsstring *datestring = @ "2015-07-16 am 11:52:49";
[Formatter settimezone: [nstimezone systemtimezone]];
[Formatter setdateformat:@ "Yyyy-m-dd aHH:mm:ss"];
nsdate *datefromstring =[formatter datefromstring:d atestring];
NSDate and NSDateFormatter Use tips