Good morning all, I am looking to create a function in swift and I ask for your help. The purpose of the code is to convert a time date expressed in UTC or GMT around a date time expressed for a time zone (timezone) Syntax: DateTimeUTCToTimezone (, )
Example:
DateTimeUTCToTimezone ("201312311200", "Africa/Abidjan")
- This should return "201312311200" because "Africa/Abidjan" is in GMT 0
DateTimeUTCToTimezone ("201312311200", "Europe/Paris")
- This should return "201312311300" because "Europe/Paris" is in GMT 1
DateTimeUTCToTimezone ("201309011200", "Europe/Paris")
- This should return "201309011400"
and so on
I managed to create my function generates an execution error on the line
return dateFormatter.string(from: dt!)
here is the error message
Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1003aa100)
I'm new to swift and I don't know what to do.
here is the full code:
func DateHeureUTCVersTimezone(dateString:String ,TimezoneId:String) -> String
{
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMddHHmmss"
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
let dt = dateFormatter.date(from: dateString)
dateFormatter.timeZone = TimeZone(identifier : TimezoneId)
dateFormatter.dateFormat = "yyyyMMddHHmmss"
return dateFormatter.string(from: dt!)
}
ss
from your formatter. – Savca Marin Feb 27 '20 at 13:36