Obj-C Date - If earlier, make it tomorrow
-
27-10-2019 - |
سؤال
I have an NSDate object, and I need to check if it has already passed. If so, turn that date into the date of tomorrow, but I can't lose information like TimeZone in the process.
Could you plz help me?
المحلول
NSDate
has no timezone info. It's just a thin layer over the number of seconds elapsed since its epoch. You can use a calendar and a timezone to turn it into an NSDateComponents
, fiddle with the date there, and then format that into a new NSDate
.
نصائح أخرى
NSDate *date = ...;
if ([[NSDate date] timeIntervalSinceDate:date] > 0) {
date = [date dateByAddingTimeInterval:24*60*60];
}
لا تنتمي إلى StackOverflow