BlaBla974 BlaBla974 - 1 year ago 88
iOS Question

iOS - Number of milliseconds since midnight 01 January, 1970 UTC

I know this is a frequently asked question, but there is something I don't understand.

Why does this code in Javascript doesn't give me the same result in objectiv C :

var date = new Date();
console.log("date since 1970 = " + date.valueOf());

result =
date since 1970 = 1480323993778

NSDate *date = [NSDate date];
NSLog(@"date since 1970 = %f", [date timeIntervalSince1970]);

result =
date since 1970 = 1480323995.950330

I'm currently working on moon calculation for moonrise and moonset, and my values are totally different from the implementation I found in Javascript.
That's why I'm guessing it's a Date and Time issue.

Answer Source

The Java Code returns an invalid timestamp: 1480323993778 = > Mon, 07 Aug 48879 13:22:58 GMT while the obj-c result is correct 1480323995.950330 => Mon, 28 Nov 2016 09:06:35 GMT. You should check the java code again. Thats why you get different results. (Try long unixTime = System.currentTimeMillis() / 1000L;)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download