// // DRIncomeDateTool.m // YouHuiProject // // Created by 小花 on 2018/8/8. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRIncomeDateTool.h" @implementation DRIncomeDateTool + (NSString *)getTodayString { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd"]; NSDate *datenow = [NSDate date]; NSString *currentTimeString = [formatter stringFromDate:datenow]; return currentTimeString; } + (NSString *)getYestodayString { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd"]; NSDate * date = [NSDate date];//当前时间 NSDate *lastDay = [NSDate dateWithTimeInterval:-24*60*60 sinceDate:date];//前一天 NSString *currentTimeString = [formatter stringFromDate:lastDay]; return currentTimeString; } + (NSString *)getThisMonthString { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM"]; NSDate *datenow = [NSDate date]; NSString *currentTimeString = [formatter stringFromDate:datenow]; return currentTimeString; } + (NSString *)getLastMonthString { NSDate *currentDate = [NSDate date]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM"]; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; NSDateComponents *lastMonthComps = [[NSDateComponents alloc] init]; // [lastMonthComps setYear:1]; // year = 1表示1年后的时间 year = -1为1年前的日期,month day 类推 [lastMonthComps setMonth:-1]; NSDate *newdate = [calendar dateByAddingComponents:lastMonthComps toDate:currentDate options:0]; NSString *dateStr = [formatter stringFromDate:newdate]; return dateStr; } @end