ma1*_*w28 3 iphone objective-c mongodb bson
我发现了这个:
功能:http://github.com/timburks/NuMongoDB/blob/master/src/bson.c#L128 bytes:http://github.com/timburks/NuMongoDB/blob/master/src/platform_hacks.h#L55 struct: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;
}
Run Code Online (Sandbox Code Playgroud)
马特
您可以将oid字符串转换为NSDate,如下所示:
NSString *asd = @"4c8f695bdaf9856dbe000008";
long result;
BOOL success = [[NSScanner scannerWithString:[asd substringToIndex:8]] scanHexLongLong:&result];
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:result];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1454 次 |
| 最近记录: |