xxxxxxxxxx
import Foundation
// Define the UTC time string
let utcTimeString = "10:30"
// Create a DateFormatter instance
let dateFormatter = DateFormatter()
// Set the input format as UTC time
dateFormatter.dateFormat = "HH:mm"
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
// Parse the UTC time string and convert it to a Date object
guard let utcDate = dateFormatter.date(from: utcTimeString) else {
print("Invalid time format")
// Handle the invalid time format case
return
}
// Set the desired output time zone
dateFormatter.timeZone = TimeZone.current
// Format the date to the user's local time
let localTime = dateFormatter.string(from: utcDate)
// Print the local time
print("Local Time: \(localTime)")