When I try to print the user selected date within the below function, I get a date 1 day lesser than the selected date. This happens even in the calendar tutorial examples
Please suggest, How I could fix this issue ?
func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleDayCellView?, cellState: CellState) {
handleCellSelection(view: cell, cellState: cellState)
handleCellTextColor(view: cell, cellState: cellState)
selectedDate.text = String(describing: date)
print("Date \(date)")
}

Date is correct.
You just need to format it.
Let me know if the following helps you --> https://github.com/patchthecode/JTAppleCalendar/issues/252#issuecomment-270436780
When dealing with Dates, printing it to the console will give you incorrect results depending on your timeZone. Never simply print a date. The correct way to handle dates is to use DateFormatters if you want the correct date printed to console.
If you still need help on this, I'll be available in the morning.
Your fix is simple. Create a DateFormatter, then set its timeZone and locale to be the same as the calendar() instance you supplied in the configureCalendar function. Then simply print the stringFromDate
Thanks again, I got it working by using the below code:
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
print("printing current Date\(formatter.string(from: date))")
Most helpful comment
Date is correct.
You just need to format it.
Let me know if the following helps you --> https://github.com/patchthecode/JTAppleCalendar/issues/252#issuecomment-270436780
When dealing with
Dates, printing it to the console will give you incorrect results depending on your timeZone. Never simplyprinta date. The correct way to handle dates is to useDateFormattersif you want the correct date printed to console.