title: How to display only the hours when minutes are zero with date formatter?
body: <p>Am currently using the format <code>MM-dd-yyyy HH:mm</code> to display the time stamp. Is it possible to drop the minutes if the time does not have any minute component ?</p>
  
  <p>Like, instead of <code>3:00 PM</code> is it possible to display only <code>3 PM</code> ?</p>
  
  <p>EDIT:</p>
  
  <pre><code>func formatDate(_ dateFormat: String, timeInterval: TimeInterval) -&gt; String {
      let date = Date(timeIntervalSince1970: timeInterval)
      let formatter = DateFormatter()
  
      formatter.dateFormat = dateFormat
      return formatter.string(from: date) 
  }
  
  let formattedDate = formatDate("MM-dd-yyyy HH:mm", timeInterval: 1520422200)
  print(formattedDate)
  </code></pre>