どうも、ちょげ(@chogetarou)です。
Dateで明日の日付を取得する方法を紹介します。
方法

Dateで明日の日付を取得するには、Calendarを使います。
まず、Caledar.current.date()を呼び出します。
次に、Calendar.current.dateの引数「byAdding」に「.date」、引数「value」に「1」を指定します。
そして、引数「to」に今日の日付を指定します。
var tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: today)
Calendarを使って、今日の日付を+1することで、明日の日付を取得することが出来ます。
使用例
let today = Date()
let tomorrow = Calendar.current.date(byAdding: .day,value: 1, to: Date())!
print(today) //2022-03-24 19:47:05 +0000
print(tomorrow) //2022-03-25 19:47:05 +0000
オススメの記事
コメント