The NSDate object is used to represent a specific point in time.
1 #import<Foundation/Foundation.h>2 3 intMainintargcConst Char*argv[]) {4 @autoreleasepool {5 //String Turn Time6NSString *time =@"2020/10/01 08:00:00";7NSDateFormatter *dateformat =[[NSDateFormatter alloc] init];8Dateformat.dateformat =@"YYY/MM/DD HH:mm:ss";9NSDate *date =[DateFormat datefromstring:time];TenNSLog (@"%@", date); One } A return 0; - } - the /** Simple use of nsdate*/ - voidUse () - { - //creation Time +NSDate *date =[NSDate Date]; - + //the time to print is Greenwich Mean Time (Beijing in the East 8 district) ANSLog (@"%@", date); at -NSDate *date2 = [NSDate datewithtimeinterval:5Sincedate:date]; - - //description of the walk from 1970 onwards -Nstimeinterval seconds =[Date2 timeIntervalSince1970]; -NSLog (@"%f", seconds); in - [Date2 Timeintervalsincenow]; to + } - the * /** Time Turn string*/ $ voiddate2string ()Panax Notoginseng { -NSDate *date =[NSDate Date]; the + //Date Formatting class ANSDateFormatter *formatter =[[NSDateFormatter alloc] init]; the + //y year M month D Day - //m min S second h (24) H (12) $Formatter.dateformat =@"YYY-MM-DD HH:mm:ss"; $NSString *str =[Formatter stringfromdate:date]; -NSLog (@"%@", str); -}
The use of the nsdate of the 7.Foundation frame