title: Incorrect time in Date from 12-Hr format Time String - Swift
body: <p>I have following strings as 12-Hr format time:</p>
  
  <pre><code>let timeFrom = "05:30 AM";
  let timeTo = "04:35 PM";
  </code></pre>
  
  <p>And trying to get date from these for comparison as follows:</p>
  
  <pre><code>let openTime = timeFrom.date(format: "hh:mm a")
  let closeTime = timeTo.date(format: "hh:mm a")
  </code></pre>
  
  <p>With this extension :</p>
  
  <pre><code>extension String
  {
      func date(format:String) -&gt; Date?
      {
          let formatter = DateFormatter()
          formatter.dateFormat = format
          formatter.timeZone = NSTimeZone.local
          return formatter .date(from: self)
      }
  }
  </code></pre>
  
  <p>When I print openTime and closeTime, I'm getting incorrect values in time:</p>
  
  <pre><code>print(openTime)      // 2000-01-01 00:00:00 +0000
  print(closeTime)     // 2000-01-01 11:00:00 +0000
  </code></pre>
  
  <p>Why this is so ? I think it is smoething related to time zone, so I visit <a href="https://stackoverflow.com/questions/29407599/nsdateformatter-return-wrong-date-swift">NSDateFormatter return wrong date + Swift</a>, but nothing worked for me. If anybody have the solution, please help me. Thank you !</p>