猎豆优选

DateFunction.m 923B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // DateFunction.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/8.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DateFunction.h"
  9. @implementation DateFunction
  10. + (int)intervalSinceNow: (NSString *)theDate {
  11. NSDateFormatter *date=[[NSDateFormatter alloc] init];
  12. [date setDateFormat:@"yyyy-MM-dd"];//设置时间格式//很重要
  13. NSDate *d=[date dateFromString:theDate];
  14. NSTimeInterval late=[d timeIntervalSince1970]*1;
  15. NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
  16. NSTimeInterval now=[dat timeIntervalSince1970]*1;
  17. NSString *timeString=@"";
  18. NSTimeInterval cha=late-now;
  19. if (cha/86400>1) {
  20. timeString = [NSString stringWithFormat:@"%f", cha/86400];
  21. timeString = [timeString substringToIndex:timeString.length-7];
  22. return [timeString intValue];
  23. }else if(cha/86400 <= 1){
  24. return 1;
  25. }
  26. return 0;
  27. }
  28. @end