12345678910111213141516171819202122232425262728293031323334 |
- //
- // DateFunction.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/8.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DateFunction.h"
- @implementation DateFunction
- + (int)intervalSinceNow: (NSString *)theDate {
- NSDateFormatter *date=[[NSDateFormatter alloc] init];
- [date setDateFormat:@"yyyy-MM-dd"];//设置时间格式//很重要
- NSDate *d=[date dateFromString:theDate];
-
- NSTimeInterval late=[d timeIntervalSince1970]*1;
- NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
- NSTimeInterval now=[dat timeIntervalSince1970]*1;
- NSString *timeString=@"";
- NSTimeInterval cha=late-now;
- if (cha/86400>1) {
- timeString = [NSString stringWithFormat:@"%f", cha/86400];
- timeString = [timeString substringToIndex:timeString.length-7];
- return [timeString intValue];
- }else if(cha/86400 <= 1){
- return 1;
- }
- return 0;
- }
- @end
|