I am using device time to get date components. this works fine for 12 hours formate but if user changes device time to 24 hours it shows wrong calculations. used the following method to convert but it always return nil.
let dateAsString = "\(Date())"
let df = DateFormatter()
df.dateFormat = "yyyy-mm-dd HH:mm:ss zzz"
let date = df.date(from: dateAsString)
df.dateFormat = "d MMM yyyy h:mm a"
let time12 = df.string(from: date!)
print(time12)