我有两次:
10:23:51
10:31:54
这两个值都作为字符串存储在SQLite数据库中。
我想以hh:mm格式查找这两次之间的差异。
我怎样才能做到这一点?
我搜了很多。但是找不到合适的解决方案。
帮帮我。
谢谢。
编辑:
基本上,我有两个数组:InTimeArray
和OuttimeArray
。
现在,在viewDidload
方法中,我将获取intime
数组中的IntimeArray
和Outtime
条目中的所有outtime
条目。
现在我像第1行一样在tableview中一一传递值
IntimeArray[0]
OuyTimeArray[0]
第二行:
IntimeArray[1]
OuyTimeArray[1]
现在,我想计算HH:MM格式的第一行
intime
和outtime
之间的差异。我真的很困惑。
最佳答案
您可以看一下:
-(NSDate *)dateFromString:(NSString *)string
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormat setLocale:locale];
[dateFormat setDateFormat:@"HH:mm:ss"];
NSDate *date1 = [dateFormat dateFromString:string];
if(!date1) date1= [NSDate date];
[dateFormat release];
[locale release];
return date1;
}
这将使NSDate变为您,当您将它们都更改为NSDate时,您可以通过查看this来了解不同之处。
我希望这能帮到您..
关于iphone - iPhone两次之间的时差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10448211/