NSDate
NSDate是时间类,可以创建一个时间点的对象。
//返回当前时间(格林尼治时间)
NSDate *currentDate = [NSDatedate];
//返回以当前时间为准的一分钟后
NSDate *date = [NSDatedateWithTimeIntervalSinceNow:60];
//返回以2001/01/01 GMT为基准,然后过了60秒的时间
NSDate *date2 = [NSDatedateWithTimeIntervalSinceReferenceDate:60];
//返回以1970/01/01 GMT为基准,然后过了60秒的时间
NSDate *date3 = [NSDatedateWithTimeIntervalSince1970:60];
//返回很多年前的一天
NSDate *date4 = [NSDatedistantPast];
//返回很多年后的一天
NSDate *date5 = [NSDatedistantFuture];
//返回date距离现在多少秒
NSTimeInterval secs = [datetimeIntervalSinceNow];
NSDateFormatter 时间戳,用于显示时间
NSTimeZone 时区类,用于时区转换
//创建时间戳
NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];
//自定义时间的打印格式
dateFormatter.dateFormat =@"yyyy年MM月dd日 HH:mm:ss";
//设置时区为香港
dateFormatter.timeZone = [NSTimeZonetimeZoneWithAbbreviation:@"HKT"];
NSLog(@"%@",[dateFormatterstringFromDate:currentDate]);
//获取当日时间
NSDate *time = [NSDate date];
NSDateFormatter *fommater = [[NSDateFormatter alloc]init];
[fommater setDateFormat:@"yyyy-MM-dd"];
_strData = [fommater stringFromDate:time];