OrangePot
OrangePot

Reputation: 1092

Custom NSDateFormatter.timeZone - Swift

Im currently creating timezones with the following format:

    let ukTz = NSDateFormatter();
    ukTz.dateFormat = "HH:mm";
    ukTz.timeZone = NSTimeZone(name: "Europe/London")

I'd like to make a similar variable in my code, but for Myanmar (UTC +6:30). Myanmar seems to be the only country in this timezone, and there is no NSTimeZone(name: "Asia/Yangon"). Is there a way i can do this by specifying "UTC+6.30"?

Upvotes: 2

Views: 776

Answers (1)

Martin R
Martin R

Reputation: 540075

You can create a time zone with a given GMT offset:

let tz = NSTimeZone(name: "GMT+0630") // or
let tz = NSTimeZone(name: "UTC+0630") // or
let tz = NSTimeZone(forSecondsFromGMT: 6 * 3600 + 30 * 60)

But what you are probably looking for is

let tz = NSTimeZone(name: "Asia/Rangoon")

(using the english name for Yangon).

Upvotes: 5

Related Questions