title: ios Swift Date without Time
body: <p>I am trying to get only date that means hours, mins, seconds are zeroes. This is what i am trying</p>
  
  <pre><code>extension Date {
  
      var onlyDate: Date? {
          get {
              let calender = Calendar.current
              var dateComponents = calender.dateComponents([.year, .month, .day], from: self)
              dateComponents.timeZone = NSTimeZone.system
              return calender.date(from: dateComponents)
          }
      }
  
  }
  </code></pre>
  
  <p>When i try </p>
  
  <pre><code>date = Date().onlyDate 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7QItS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7QItS.png" alt="My Output"></a></p>
  
  <p>It returns the previous date. You can check the screenshot that its giving me 14th April while it should have been 15th</p>