nstimezone

iPhone - Differences among time zone convenience methods

本秂侑毒 提交于 2019-11-26 15:18:22
问题 I see that NSTimeZone has these methods : defaultTimeZone localTimeZone systemTimeZone Can someone explain to me, in simple terms, what the differences are beetween those calls, and when one should be used instead of the other? I don't understand anything inside the Apple docs about this. 回答1: The language in the docs is a bit on the dry side, to be sure, and the similarity of the names is potentially confusing. I'll quote the NSTimeZone docs here and try to explain them: systemTimeZone The

How to get a user's time zone?

孤人 提交于 2019-11-26 12:02:49
Does anyone know of a way to get a users time zone in Swift? I'm getting a specific time something is on t.v. out of a database and then need to subtract/add from where they are located to show them the correct time it's on. edit/update: Xcode 8 • Swift 3 var secondsFromGMT: Int { return TimeZone.current.secondsFromGMT() } secondsFromGMT // -7200 if you need the abbreviation: var localTimeZoneAbbreviation: String { return TimeZone.current.abbreviation() ?? "" } localTimeZoneAbbreviation // "GMT-2" if you need the timezone name: var localTimeZoneName: String { return TimeZone.current.identifier

How to get a user's time zone?

北慕城南 提交于 2019-11-26 02:06:07
问题 Does anyone know of a way to get a users time zone in Swift? I\'m getting a specific time something is on t.v. out of a database and then need to subtract/add from where they are located to show them the correct time it\'s on. 回答1: edit/update: Xcode 8 or later • Swift 3 or later var secondsFromGMT: Int { return TimeZone.current.secondsFromGMT() } secondsFromGMT // -7200 if you need the abbreviation: var localTimeZoneAbbreviation: String { return TimeZone.current.abbreviation() ?? "" }