LoginSignup
8

More than 5 years have passed since last update.

翌日の0:00のNSDateを受け取る

Posted at

日付が変わった瞬間にNSTimerを実行したい時とかに使えます。


NSDate* nextDate = [NSDate dateWithTimeIntervalSinceNow:1*24*60*60];// 翌日の日付を取得。

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy/MM/dd"];    // 日付だけ取得できるフォーマットで情報を抽出。

NSString* nextDateString = [dateFormatter stringFromDate:nextDate];
[dateFormatter setDateFormat:@"yyyy/MM/dd hh:mm:ss"];   // 時間を含めたフォーマットで日付を設定する。

NSDate* fireDate = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@ 00:00:00", nextDateString]]; // 翌日の0:00のNSDateが完成。

もっと効率の良い方法があったら教えて下さい(^^;

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8