需要有关将 UIDatePicker 时间转换为时间戳的帮助
Need assistance regarding converting UIDatePicker time to timestamp
我正在尝试将 UIDatePicker
小时和分钟转换为这样的时间戳
- (IBAction)datePickerValueChanged:(id)sender {
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"hh:mm a"];
[outputFormatter setTimeZone:[NSTimeZone defaultTimeZone]];
self.timeLbl.text = [outputFormatter stringFromDate:self.theDatePicker.date];
NSTimeInterval ti = [self.theDatePicker.date timeIntervalSince1970];
NSString *sit = [NSString stringWithFormat:@"%f", ti];
NSLog(@"%@", sit);
}
我想将 UIDatePicker
小时和分钟转换为时间戳而不是秒。如何做到这一点?因为我正在通过这个网站 http://www.epochconverter.com/ 进行测试,但我正在设置秒数。我想要 11:05 am/pm 而不是秒数。
[outputFormatter stringFromDate:self.theDatePicker.date]
生成您需要的字符串。只是 NSLog this 而不是 sit。
我正在尝试将 UIDatePicker
小时和分钟转换为这样的时间戳
- (IBAction)datePickerValueChanged:(id)sender {
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"hh:mm a"];
[outputFormatter setTimeZone:[NSTimeZone defaultTimeZone]];
self.timeLbl.text = [outputFormatter stringFromDate:self.theDatePicker.date];
NSTimeInterval ti = [self.theDatePicker.date timeIntervalSince1970];
NSString *sit = [NSString stringWithFormat:@"%f", ti];
NSLog(@"%@", sit);
}
我想将 UIDatePicker
小时和分钟转换为时间戳而不是秒。如何做到这一点?因为我正在通过这个网站 http://www.epochconverter.com/ 进行测试,但我正在设置秒数。我想要 11:05 am/pm 而不是秒数。
[outputFormatter stringFromDate:self.theDatePicker.date]
生成您需要的字符串。只是 NSLog this 而不是 sit。