Reputation: 3045
In my game players will be able to plant a tree, which will take 3 hours to grow. When the player logs back in how would I calculate whether that tree is now fully grown? the creation date of the tree (planted) will be stored on a server, and I will be storing the 3 hours in seconds (not sure if that should be an int of NSNumber) also on the server.
Thanks for any help.
Upvotes: 0
Views: 63
Reputation: 960
Get your creation date back from the server as an NSDate
, and use timeIntervalSinceDate:
like so:
NSDate *now = [NSDate date];
NSTimeInterval secondsSincePlanting = [now timeIntervalSinceDate:plantingDate];
if (secondsSincePlanting > secondsRequiredForTreeToFullyGrow) {
...
}
Upvotes: 1