Substracting 1 hour from a nstimeinterval value

1.3k Views Asked by At

Can we substract (say 1 hour) from the given nstimeinterval eg: 1416528000.000000 ?

  NSDate *  today1 = [NSDate date];
  NSTimeInterval  today = [today1 timeIntervalSince1970];

Substracting 1 hour from today?

2

There are 2 best solutions below

0
On BEST ANSWER

A NSTimeInterval is measured in seconds. If you substract 3600 from it, you'll go back one hour in time (60 minutes * 60 seconds per minute).

0
On

You can add or subtract time (in seconds) to get a new time interval. You can also use this code to get time interval since 1970 - N hour,

[[[NSDate date] dateByAddingTimeInterval:-N * 60] timeIntervalSince1970];