سؤال

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];
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top