IPhone: converting an Oracle timestamp to NSDate or to a Unix timestamp (e.g. double)

Is there a good + easy way to convert Oracle Timestamp to NSDate on iPhone? I asked my client to give me a DB with timestamps as a Unix timestamp (doubles from 0 = early 1970), but it seems to be a problem for them. Thank.

Note. You can easily convert Unix timestamp to NSDate with

[NSDate dateWithTimeIntervalSince1970: timestamp]  // timestamp is a "double"

What I need to do is convert the Oracle timestamp to double, for example, a Unix timestamp. The rest is easy.

Additional Information: I need Objective-C code to run on iPhone using NSStrings that represent dates in Oracle Timestamp format. Stack Overflow.site/questions/1734268 / ... suggests using NSDateFormatter, but I don’t know which format to use, and the initialization method for formatting proposed in this thread generates a warning for me.

+3
source share
3 answers

I'm not sure about converting to NSDate, but you can easily convert Oracle date to unix timestamp. The following SQL fragment will do this:

(my_date - to_date('01/01/1970','DD/MM/YYYY')) * 86400
+2
source

It seems like my best bet is to use the following:

NSDateFormatter* formatter = [[NSDateFormatter alloc] init];    
[formatter setDateFormat:@"MM/dd/yyyy HH:mm a"];

, Oracle timestamps, , , .

. , .

+2

It's a shame that you already accepted this answer, but this is the best way to do this:

NSDate *dateTraded = [NSDate dateWithTimeIntervalSince1970 :[timestampVal integerValue]];

... where timestampVal is an NSString object representing the timestamp value.

+2
source

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


All Articles