0

In objective c:

NSDate *past = [NSDate date];
NSTimeInterval oldTime = [past timeIntervalSince1970];
NSString *timestamp = [[NSString alloc] initWithFormat:@"%0.0f", oldTime];

in Javascript:

new Date().getTime();

The problem is that in objective c the timestamp consists of 10 numbers, however in javascript it has 13 numbers. When I compare the difference of both is within 15 minutes I get always false.

Any ideas how to get a 13 digit timestamp in objective c?

1 Answer 1

2

getTime() http://www.w3schools.com/jsref/jsref_gettime.asp

Returns the number of milliseconds since 1970/01/01:

- (NSTimeInterval)timeIntervalSince1970

Returns the interval between the receiver and the first instant of 1 January 1970, GMT.
NSTimeInterval used to specify a time interval, in seconds.

So you need to multiply value by 1000 to convert seconds to milliseconds

NSDate *past = [NSDate date];
NSTimeInterval oldTime = [past timeIntervalSince1970];
NSString *timestamp = [[NSString alloc] initWithFormat:@"%0.0f", oldTime * 1000];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.