How do I get the next and earlier date of the current date in iPhone sdk -


I have a date object,

NSDate * date = [NSDate date];

Now I need a date before and after this date.

Meaning before and after one day and a day later.

Besides, I tried to use the first date but maybe I am misusing it because it is returning only one date.

tnx

NSDT is a bit of a misnomer. This is not a simple date, it is a date, which is with subsecond level precision. First date: The method is a comparative task that returns to the first of two dates, it is not making the date of the earlier date. If you care about everyone, then it is the date that is before your current one that you can do:

  NSDate * first date = [date addTimeInterval: -1.0];  

will return 1 second before the date. Similarly you can

  NSDate * later date = [date addTimeInterval: 1.0]; In the future, a date for 1 second  

.

If you want the day before, you can add the day worth the second. Of course, unless you have to deal with all Gregorian calendar issues, but if you want a quick approximation then:

  NSDate * earlierDate = [date addTimeInterval: (- * 1.0 * 24 * 60 * 60)];  

This does not work with lip seconds etc. But for most uses this is probably OK.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -