- (NSDictionary*)getCuttentDayPeriod {
NSDate*date = [NSDate date];
NSCalendar*calendar = [NSCalendar currentCalendar];
NSDateComponents*comps = [calendar components:NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit fromDate: date];
[comps setHour:0];//设置开始时间为0点
NSDate*beginDate =[calendar dateFromComponents:comps];
NSDate*endDate = [beginDate dateByAddingTimeInterval:3600*24-1];
NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
formatter.dateFormat=@"yyyy-MM-dd HH:mm:ss";
NSString* startTime = [formatterstringFromDate:beginDate];
NSString* endTime = [formatterstringFromDate:endDate];
NSDictionary*dct = [[NSDictionary alloc] initWithObjects:@[startTime, endTime]forKeys:@[@"StartTime",@"EndTime"]];
return dct;
}
网友评论