self.timePicker.datePickerMode = UIDatePickerModeCountDownTimer;
上面的是获取24小时进制的方法。
[formatter setDateFormat:@"HH:mm"]; 里面的HH 是24小时,而hh 是12进制的。
UIDatePicker* control = (UIDatePicker*)sender;
NSDateFormatter *formatter = [[[NSDateFormatteralloc] init] autorelease];
[formatter setDateFormat:@"HH:mm"];
//这个时间应该存起来。
NSDate *tempTime = control.date;
NSLog(@"tempTime == %@",tempTime);
NSString *timeString = [formatter stringFromDate:tempTime];
NSLog(@"timeString == %@",timeString);
if (timeFlag == 2) {
self.secondDate = control.date;
self.secondDate2 = timeString;
self.timeTextField2.text = timeString;
}else{
self.firstDate = control.date;
self.firstDate2 = timeString;
self.timeTextField1.text = timeString;
}
取的时候也不用减去8个小时,只有下面的方法的时候才要减8个小时
+(NSString *)fromTimeChuoTotime2:(NSString *)timeChuo{
NSDateFormatter *formatter = [[[NSDateFormatteralloc] init] autorelease];
[formatter setDateFormat:@"HH:mm"];//小写h是12进制的。大写的才是24进制的。
NSDate *myDate = [NSDatedateWithTimeIntervalSince1970:[timeChuo doubleValue]];
NSDate *myDate2 = [NSDate dateWithTimeInterval:-8*3600 sinceDate:myDate];
NSString *myDateString = [formatter stringFromDate:myDate2];
return myDateString;
}
// NSTimeZone *zone = [NSTimeZone systemTimeZone];
// NSInteger interval = [zone secondsFromGMTForDate: date];
// NSDate *nowDate = [date dateByAddingTimeInterval: interval];
// NSLog(@"enddate=%@",nowDate);