《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRIncomeDateTool.m 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // DRIncomeDateTool.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/8/8.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRIncomeDateTool.h"
  9. @implementation DRIncomeDateTool
  10. + (NSString *)getTodayString {
  11. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  12. [formatter setDateFormat:@"yyyy-MM-dd"];
  13. NSDate *datenow = [NSDate date];
  14. NSString *currentTimeString = [formatter stringFromDate:datenow];
  15. return currentTimeString;
  16. }
  17. + (NSString *)getYestodayString {
  18. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  19. [formatter setDateFormat:@"yyyy-MM-dd"];
  20. NSDate * date = [NSDate date];//当前时间
  21. NSDate *lastDay = [NSDate dateWithTimeInterval:-24*60*60 sinceDate:date];//前一天
  22. NSString *currentTimeString = [formatter stringFromDate:lastDay];
  23. return currentTimeString;
  24. }
  25. + (NSString *)getThisMonthString {
  26. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  27. [formatter setDateFormat:@"yyyy-MM"];
  28. NSDate *datenow = [NSDate date];
  29. NSString *currentTimeString = [formatter stringFromDate:datenow];
  30. return currentTimeString;
  31. }
  32. + (NSString *)getLastMonthString {
  33. NSDate *currentDate = [NSDate date];
  34. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  35. [formatter setDateFormat:@"yyyy-MM"];
  36. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  37. NSDateComponents *lastMonthComps = [[NSDateComponents alloc] init];
  38. // [lastMonthComps setYear:1]; // year = 1表示1年后的时间 year = -1为1年前的日期,month day 类推
  39. [lastMonthComps setMonth:-1];
  40. NSDate *newdate = [calendar dateByAddingComponents:lastMonthComps toDate:currentDate options:0];
  41. NSString *dateStr = [formatter stringFromDate:newdate];
  42. return dateStr;
  43. }
  44. @end