0

I know that to get the current time, all you have to do it declare a variable as such:

var currentTime = Date()
print(currentTime)

will print something like 2020-07-09 07:00:00 +0000

Is there such as way that I can get the current Time in a specific format yet, still maintaining the type Date?

For example, for the above 2020-07-09 07:00:00 +0000 Instead, I would like to get 2020-07-08 15:00:00 +0000

  • You can use a dateformatter. More on that over here; https://developer.apple.com/documentation/foundation/dateformatter –  Jul 09 '20 at 07:09
  • Isn't the expected and the current response same in your example? – PGDev Jul 09 '20 at 07:12
  • You meant `var currentTime = Date()` – Leo Dabus Jul 09 '20 at 07:17
  • A `Date` is an absolute point in time. It does not have a format. See also [NSDate() or Date() shows the wrong time](https://stackoverflow.com/q/39937019). – Martin R Jul 09 '20 at 07:25

0 Answers0