How can I get the current timezone in MacOS using swift 3.0 in the format “(UTC +5:30) Bombay, Calcutta, Madras, New Delhi”. As of now, I am getting it "IST": "Asia/Calcutta”.
The problem is, from our windows system we are getting the timezone as “(UTC +5:30) Bombay, Calcutta, Madras, New Delhi”, I want the same timezone format in MacOS as well.
I could come up with following with the solution provided in link How to get a user's time zone?
let secondsFromGMT = TimeZone.current.secondsFromGMT()
let hrsfromGMT = secondsFromGMT/3600
NSLog("hrsfromGMT \(hrsfromGMT)")
let remainingminutes = (Double(secondsFromGMT)
.truncatingRemainder(dividingBy: 3600))/60
NSLog("remainingminutes \(remainingminutes)")
let localTimeZoneIdentifier =
TimeZone.current.identifier.replacingOccurrences(of: "/", with: ",", options: .literal, range: nil)
let utcoffset = String(format: "%02d:%02d", hrsfromGMT,Int(remainingminutes))
let utcoffset = String(format: "%02d:%02d", hrsfromGMT,Int(remainingminutes))
messageBuilderObj.timezone = "(UTC+"+utcoffset+") "+localTimeZoneIdentifier
with this I am getting output as //"(UTC+05:30) Asia,Kolkata" instead of //"(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi". Please feel free to modify the code and suggest any solutions