0

I want to show current time in an UILabel.To get current time I use following code

extension Date {
func toMillis() -> Int64! {
    return Int64(self.timeIntervalSince1970 * 1000)
    }
}

And use the function as:

let currentTime = Date().toMillis()

it returns a value of 18 digits like that 1533013044694 how could I convert it into human readable format.Is there any other way get current time and date?

Usman
  • 171
  • 1
  • 12
  • 2
    Date() already contains current time. Use DateFormatter to convert it to a string. – Sulthan Jul 31 '18 at 05:25
  • Your `toMillis()` function has no use for converting the `Date` to a human readable date. As stated, use `DateFormatter`. There are countless examples. – rmaddy Jul 31 '18 at 05:27
  • Unrelated but why is your `toMillis` function declared to return an implicitly unwrapped value? That `!` is unnecessary. – rmaddy Jul 31 '18 at 05:28
  • When reviewing the duplicate, use the answer making use of `DateFormatter` and not the answer use `DateComponents`. – rmaddy Jul 31 '18 at 05:38

0 Answers0