0

I am trying to save data to a database and am using a date that shows seconds as the key but I want to show a smaller date in the value that is going to be displayed. The problem is to use the date formatter you need to set it like this and I cant figure out how to set another one without overwriting the current format.

DateFormatter.dateFormat = "MM-dd-yy hh:mm:ss a"
Branson
  • 77
  • 9
  • You can create multiple DateFormatter objects. Various examples can be found on [this question](http://stackoverflow.com/questions/28489227/swift-ios-dates-and-times-in-different-format). – Caleb Mar 15 '17 at 17:38
  • 1
    Possible duplicate of [Swift - iOS - Dates and times in different format](http://stackoverflow.com/questions/28489227/swift-ios-dates-and-times-in-different-format) – Caleb Mar 15 '17 at 17:39

1 Answers1

2

This is how to have multiple DateFormatter in a single View.

Formatter1

let formatter = DateFormatter()
 formatter.dateFormat = "QQQQ\ryyyy" //Shows Financial Quarter for Date
 let formattedDate = formatter.string(from: date)

Formatter2

let formatter1 = DateFormatter()
 formatter1.dateFormat = "EEEE, MMM d, yyyy" //Wednesday, Mar 29, 2017
 let formattedDate1 = formatter1.string(from: date)

Refer to this site to know more about DateFormatter. Hope this helps. Happy Coding !

Md. Ibrahim Hassan
  • 5,359
  • 1
  • 25
  • 45