使用 NSDateFormatter 从 VBO 文件解析 date/timestamp
Parsing date/timestamp from VBO file with NSDateFormatter
我正在尝试找出这种时间戳格式,但我觉得它很奇怪。
有该格式的时间戳:184930.60
解释是:"This is UTC time since midnight in the form HH:MM:SS.SS."
它看起来像秒数(根据文件的变化,对于 20Hz GPS 模块),但是将这些秒转换为 51h,而这不可能是午夜后的 51h。
知道如何将其转换为 nsdate 吗?
关于文件格式的详细信息:https://racelogic.support/01VBOX_Automotive/01General_Information/Knowledge_Base/VBO_file_format
这是工作示例:
-(NSDate *)getDateFromDecimalTime:(double)decimalTime{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HHmmss.SS"];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSDate *date = [formatter dateFromString:[NSString stringWithFormat:@"%f", decimalTime]];
//gather current calendar
NSCalendar *calendar = [NSCalendar currentCalendar];
//gather date components from date
NSDateComponents *dateComponents = [calendar components:(NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond) fromDate:date];
// Get current year/day/month
NSDate *now = [NSDate date];
// Specify which units we would like to use
unsigned units = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
NSCalendar *calendar2 = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [calendar2 components:units fromDate:now];
//set date components
[dateComponents setDay:[components day]];
[dateComponents setMonth:[components month]];
[dateComponents setYear:[components year]];
//save date relative from date
NSDate *completeDate = [calendar dateFromComponents:dateComponents];
return completeDate;
}
我正在尝试找出这种时间戳格式,但我觉得它很奇怪。
有该格式的时间戳:184930.60 解释是:"This is UTC time since midnight in the form HH:MM:SS.SS."
它看起来像秒数(根据文件的变化,对于 20Hz GPS 模块),但是将这些秒转换为 51h,而这不可能是午夜后的 51h。
知道如何将其转换为 nsdate 吗?
关于文件格式的详细信息:https://racelogic.support/01VBOX_Automotive/01General_Information/Knowledge_Base/VBO_file_format
这是工作示例:
-(NSDate *)getDateFromDecimalTime:(double)decimalTime{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HHmmss.SS"];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSDate *date = [formatter dateFromString:[NSString stringWithFormat:@"%f", decimalTime]];
//gather current calendar
NSCalendar *calendar = [NSCalendar currentCalendar];
//gather date components from date
NSDateComponents *dateComponents = [calendar components:(NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond) fromDate:date];
// Get current year/day/month
NSDate *now = [NSDate date];
// Specify which units we would like to use
unsigned units = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
NSCalendar *calendar2 = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [calendar2 components:units fromDate:now];
//set date components
[dateComponents setDay:[components day]];
[dateComponents setMonth:[components month]];
[dateComponents setYear:[components year]];
//save date relative from date
NSDate *completeDate = [calendar dateFromComponents:dateComponents];
return completeDate;
}