i have an app and user can select date from that. How to Set Tomorrow Date from selected date. For example if user select date 24 it print 25 and if user select date 31 it print 1.
Right now i'm using current date to set tomorrow's date
let dates = Date()
var tomorrow: Date {
return Calendar.current.date(byAdding: .day, value: 1, to: Date())!
}
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd"
let dateOutDefault = dateFormatter.string(from: tomorrow as Date)
How to do something like that using custom date?
import Foundation
extension Date {
var tomorrow: Date? {
return Calendar.current.date(byAdding: .day, value: 1, to: self)
}
}
let today = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd, yyyy, HH:mm b"
if let tomorrow = today.tomorrow {
let tomorrowString = dateFormatter.string(from: tomorrow)
print("\(tomorrowString)" // "Mar 23, 2017, 00:14 AM\n"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With