DaveS
1
// convert SQLDate String to Date
func SQLDateTimeToDate(_ sqldate : String) -> Date {
var sDate : String = Trim(sqldate)
if sDate.count==10 { sDate="\(sDate) 00:00:00" }
dateFormatter.dateFormat = SQLDateFormat // "yyyy-MM-dd HH:mm:ss"
// dateFormatter.locale = Locale.current
print("S=\(sDate)") // 2022-10-18 23:59:59
return dateFormatter.date(from: sDate)! // -> 2022-10-19 06:59:59 // this is UTC?!
}
This driving me CRAZY… setting Locale or not makes no difference
it ALWAYS adds the UTC TZ offset which of me is 7 hours right now
DaveS
2
Not sure why I had to do this, but it seems to work
// convert SQLDate String to Date
func SQLDateTimeToDate(_ sqldate : String) -> Date {
var sDate : String = Trim(sqldate)
if sDate.count==10 { sDate="\(sDate) 00:00:00" }
dateFormatter.dateFormat = SQLDateFormat
return local_Date(dateFormatter.date(from: sDate)!)
}
func local_Date(_ d : Date) -> Date {
let timeZoneOffset = Double(TimeZone.current.secondsFromGMT(for: d))
let localDate = Calendar.current.date(byAdding: .second, value: Int(timeZoneOffset), to: d)!
return localDate
}
dateFormatter has an attribute .timeZone. Documentation says ‘ If unspecified, the system time zone is used.’.
https://developer.apple.com/documentation/foundation/dateformatter/1411406-timezone
Haven’t tested, I am not in front of my computer.
DaveS
4
well that did not seem to be the case 
since I did not specify one
DaveS
6
which is NOT using the system timezone