NSDate *firstDate = [NSDate date];
NSLog(@"firstDate:%@",firstDate);
NSDate *secondDate = [[NSDate date] initWithTimeIntervalSinceNow:120];
NSLog(@"secondDate:%@",secondDate);
NSLog(@"earlierDate:%@",[secondDate earlierDate:firstDate]);
NSDate *threeDate = [[NSDate date] initWithTimeInterval:38 sinceDate:firstDate];
NSLog(@"===%@,***%@,---%@",firstDate,secondDate,threeDate);
NSLog(@"%@",[NSDate now]);
NSLog(@"%f",[[NSDate date] timeIntervalSince1970]);
NSDate *df_date = [NSDate distantFuture];
NSDate *dp_date = [NSDate distantPast];
NSLog(@"distantFuture:%@,distantPast:%@",df_date,dp_date);
NSLog(@"earlierDate:%@",[df_date earlierDate:dp_date]);
NSLog(@"laterDate:%@",[df_date laterDate:dp_date]);
NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
NSLog(@"系统默认时区:%@",[NSTimeZone systemTimeZone]);
//[fmt setTimeZone:[NSTimeZone systemTimeZone]];
[fmt setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Shanghai"]];
//[fmt setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:28800]];
[fmt setDateFormat:@"yyyy年MM月dd日 HH时mm分ss秒SSS毫秒"];
NSLog(@"系统时间:%@",[fmt stringFromDate:[NSDate date]]);
//时间戳转日期
NSDate *tmpDate = [NSDate dateWithTimeIntervalSince1970:1705076347];
NSString *strDate = [fmt stringFromDate:tmpDate];
NSLog(@"时间戳转日期:%@",strDate);
文章来源地址https://www.toymoban.com/news/detail-811792.html
文章来源:https://www.toymoban.com/news/detail-811792.html
到了这里,关于Objective-C日期NSDate使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!