/**
*传入时间,返回那时候的时间戳 比如今天或者明天12点的时间戳
*/
+(NSInteger )my_getFarFrom_12_TimeWithTime:(NSInteger)time
{
NSDate*date = [NSDate date];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT+0800"];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSCalendarIdentifierGregorian];
[gregorian setTimeZone:gmt];
NSDateComponents*components = [gregorian components:NSUIntegerMax fromDate: date];
[components setHour:time]; //12 36
[components setMinute:0];
[components setSecond: 0];
NSDate*newDate = [gregorian dateFromComponents: components];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSInteger timeDur = (NSInteger)[newDate timeIntervalSince1970];
return timeDur;
}
这个,传0 就是今天0点,12就是12点,24就是明天0点,36就是明天中午12点
网友评论