我发现了这个:
函数:http://github.com/timburks/NuMongoDB/blob/master/src/bson.c#L128 字节:http://github.com/timburks/NuMongoDB/blob/master/src/platform_hacks.h#L55 结构:http://github.com/timburks/NuMongoDB/blob/master/src/bson.h#L70
但是我如何将它用于我的 iPhone 应用程序,它从服务器获取 oid 作为字符串并想要提取 created_at 时间戳?这是我到目前为止所拥有的。这是一种 Objective-C 方法,但我可以将 c 代码放入我的 Objective-c .m 文件中吗?
- timeFromBsonOid:(NSString *)oid {
time_t out;
memcpy(&out, oid, 4);
return out;
}
马特
最佳答案
您可以像这样将 oid 字符串转换为 NSDate:
NSString *asd = @"4c8f695bdaf9856dbe000008";
long result;
BOOL success = [[NSScanner scannerWithString:[asd substringToIndex:8]] scanHexLongLong:&result];
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:result];
关于iphone - 将 MongoDB BSON ObjectId (oid) 转换为 Objective-C 中的生成时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3746835/