I am trying to get the current date in a time zone selected by the user, but I can't get anything other than the current date despite using functions from other answers on stackoverflow. What I used is this:
func dateIn(timeZone: TimeZone) -> Date {
let now = Date()
var calendar = Calendar.current
calendar.timeZone = timeZone
let components = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second], from: now)
let date = calendar.date(from: components) ?? Date()
return date
}
I would really appreciate it if someone could help me understand why I'm not getting the date in the time zone although I changed the time zone of calendar to that time zone.