Convert MongoDB BSON ObjectId (oid) to generated time in Objective-C?

I found this:

Function: 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

But how exactly will I use this for my iPhone application, which receives oid as a string from the server and wants to extract the created_at timestamp? This is what I still have. This is an Objective-C method, but can I put the c code in an Objective-Cm file?

- timeFromBsonOid:(NSString *)oid {
    time_t out;
    memcpy(&out, oid, 4);
    return out;
}

Matt

+3
source share
2

oid NSDate :

NSString *asd = @"4c8f695bdaf9856dbe000008";
long result;
BOOL success = [[NSScanner scannerWithString:[asd substringToIndex:8]] scanHexLongLong:&result];
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:result];
+6

Kossi . unsigned long long , 32- 64- .

NSString *asd = @"4c8f695bdaf9856dbe000008";
unsigned long long result;
BOOL success = [[NSScanner scannerWithString:[asd substringToIndex:8]] scanHexLongLong:&result];
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:result];
0

Source: https://habr.com/ru/post/1765523/


All Articles