Search code examples
timestampnsdatenstimeinterval

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


Solution

  • 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);