Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

579
Views
¿Cómo obtener la compensación de zona horaria entre UTC y iPhone - Swift 4.2?

Estoy en Swift 4.2 . Estoy luchando tratando de obtener el tiempo de compensación entre UTC y el de mi iPhone.


tengo este codigo

 extension TimeZone { func offsetFromGMT() -> String { let localTimeZoneFormatter = DateFormatter() localTimeZoneFormatter.timeZone = self localTimeZoneFormatter.dateFormat = "Z" return localTimeZoneFormatter.string(from: Date()) } }

 func getCurrentTimeZone() -> String{ return String (TimeZone.current.identifier) } var tzOffset = "" let currentTimeZone = getCurrentTimeZone() TimeZone.knownTimeZoneIdentifiers.forEach({ timeZoneIdentifier in if let timezone = TimeZone(identifier: timeZoneIdentifier) { //print("\(timezone.identifier) \(timezone.offsetFromGMT())") if(timezone.identifier == currentTimeZone){ tzOffset = timezone.offsetFromGMT() } } })

Resultado

Si lo hago

 print(tzOffset)

Obtuve

 -0500

¿Debería ser -5 ya que mi zona horaria actual es America/Montreal ?

¿Puede alguien por favor darme una pista?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede obtener la zona horaria actual, obtener la cantidad de segundos de GMT y dividirla por 3600.

 TimeZone.current.secondsFromGMT() / 3600 // -3 hs America/Sao_Paulo (current) Brazil

Si necesita más precisión, como fracción de hora, simplemente conviértalo al doble antes de dividirlo.

over 4 years ago · Santiago Trujillo Report

0

debería ser -0500 .

De la página de Wikipedia

La razón por la que tiene 4 dígitos en lugar de uno es porque está en un formato de 24 horas, y algunas zonas horarias se miden en una distancia de media hora desde UTC.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!