title: Convert Etc/GMT time into Swift Date() global TIme
body: <p>I am trying to convert date from apple receipt to swift global date and time. But I am not succeeded,</p>
  
  <p><strong>Purchased time (device):</strong> 2019-08-30 22:23:44 America/Los_Angeles</p>
  
  <p><strong>Purchased time (server):</strong> 2019-08-31 05:23:44 Etc/GMT</p>
  
  <p><strong>Expire time (server):</strong> 2019-08-31 05:28:44 Etc/GMT</p>
  
  <p>When I get date by using <code>Date()</code>, it's completely or almost some hour difference than my device &amp; those date&amp;time above. I wanted to compare today <code>Date()</code> into expire time.</p>
  
  <p>I used below codes but not success,</p>
  
  <pre><code>extension Date {
      static func fromAppleServer(dateString: String) -&gt; Date? {
          let seperated = dateString.components(separatedBy: " ")
          let dateFormatter = DateFormatter()
          dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
          dateFormatter.timeZone = TimeZone(identifier: seperated.last!)
          let dateObject = dateFormatter.date(from: (seperated.dropLast()).joined(separator: " "))
          return dateObject
      }
      static func localUTC() -&gt; Date {
          let date = Date()
          print("Date before conversion: \(date)")
          let dateFormatter = DateFormatter()
          dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
          let string = dateFormatter.string(from: date)
          dateFormatter.timeZone = TimeZone(identifier: "America/Los_Angeles")
          return dateFormatter.date(from: string)!
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>let appleDate = Date.fromAppleServer(dateString: "2019-08-30 22:29:02 America/Los_Angeles") //used  2019-08-31 05:23:44 Etc/GMT too
  let localUTC = Date.localUTC()
  
  print("Apple Server: ",appleDate) //Always 2019-08-31 05:29:02 +0000
  print("Local UTC: ",localUTC)
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>Tried code:</p>
  
  <pre><code>extension Date{
  
      static func fromAppleServer(dateString: String) -&gt; Date?{
  
          let dateFormatter = DateFormatter()
          dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss VV"
          dateFormatter.timeZone = TimeZone(identifier: "UTC")
          let dateObject = dateFormatter.date(from: dateString)
          return dateObject
      }
  
      static func localUTC() -&gt; Date{
  
          let date = Date()
          let dateFormatter = DateFormatter()
          dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss VV"
          let string = dateFormatter.string(from: date)
          dateFormatter.timeZone = TimeZone(identifier: "UTC")
          return dateFormatter.date(from: string)!
      }
  }
  </code></pre>
  
  <p><strong>Debugging Log:</strong></p>
  
  <pre><code>(lldb) po print date
      ▿ 2019-08-31 05:28:44 +0000
  - timeIntervalSinceReferenceDate : 588922124.0
  
  Fix-it applied, fixed expression was:
  print; date
  (lldb) po print Date.localUTC()
  ▿ 2019-09-01 03:07:45 +0000
  - timeIntervalSinceReferenceDate : 589000065.0
  
  Fix-it applied, fixed expression was:
  print; Date.localUTC()
  (lldb) po print self.expiryDate
  ▿ Optional&lt;String&gt;
  - some : "2019-08-31 05:28:44 Etc/GMT"
  
  Fix-it applied, fixed expression was:
  print; self.expiryDate
  (lldb) po print Date()
  ▿ 2019-09-01 03:09:03 +0000
  - timeIntervalSinceReferenceDate : 589000143.939402
  
  Fix-it applied, fixed expression was:
  print; Date()
  (lldb)
  </code></pre>
  
  <p>Here, </p>
  
  <p>Device date is ~ <code>8:mm PM, Sat 31 August</code>.
  Purchased date is(5 mins duration):<code>2019-08-31 05:23:44 Etc/GMT</code> (For device it's 8:mm PM Sat 31 August) 
  Expire date is: <code>2019-08-31 05:28:44 Etc/GMT</code>
  Swift Date is:~ <code>2019-09-01 03:09:03</code></p>
  
  <p>I thought we can easily compare date once <code>Etc/GMT</code> time is converted into Swift <code>Date()</code> global time. But I can't convert <code>2019-08-31 05:28:44 Etc/GMT</code> to  ~ <code>2019-09-01 03:09:03</code>. So, how to convert it? or Any other suggestions welcome.</p>
  
  <p>Note: '~' indicates some seconds or minutes delay because of testing time.</p>