iOS 时间类常用方法
2018-07-20 来源:open-open
NSDate *today = [NSDate date];
//时区
NSTimeZone *zone = [NSTimeZone systemTimeZone];
//设置间隔
_interval = [zone secondsFromGMTForDate: today];
//今天+8小时(中国上海时区)
today = [today dateByAddingTimeInterval: _interval];
//获取明天日期
NSDate *tomorrowDate = [[NSDate alloc]initWithTimeInterval:24 * 60 * 60 sinceDate:[NSDate date]];
//日历
NSCalendar *calendar = [NSCalendar currentCalendar];
//comps里可以分离出时间年月日等信息
NSDateComponents *comps = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit |NSWeekdayOrdinalCalendarUnit | NSHourCalendarUnit) fromDate:tomorrowDate];
//获取当前星期几
NSInteger weekday = [comps weekday];
//将NSString类型转换成NSDate
NSDate *serverDate = [dateFomatter dateFromString:serverTimeStr];
NSDate *createDate = [dateFomatter dateFromString:createTimeStr];
//算出两个Date的间隔
NSTimeInterval betweenTime = [serverDate timeIntervalSinceDate:createDate];
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:C# 获得本地IP地址
下一篇:C# 异步调用代理类