Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C timestamp is not equal to java timestamp

I am working on an application receiving data from a backend. The problem is, that the dates are not working properly in my app. So I ended up comparing the timestamps generated by cocoa and the ones generated by my java backend.

Is there any reason that the java one is much longer than the objective c one?

Just compared:

java

1318226845471

cocoa

1318226841

I am generating the cocoa timestamp with:

[[NSDate date] timeIntervalSince1970]

Any suggestions? I would appreciate any help!

Thanks in advance, Alex

like image 801
Alexander Avatar asked Feb 02 '26 03:02

Alexander


1 Answers

Java returns milliseconds since Jan 1, 1970. Objective C is seconds since Jan 1, 1970

just use in java to get the result in seconds return (int) (System.currentTimeMillis() / 1000L);

like image 102
Jeroen Coupé Avatar answered Feb 05 '26 05:02

Jeroen Coupé



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!