Date Format in Swift
In this story, i will use one simple function that will take two parameters, and covert it to new formatted date.
1. This is the simple function i will use to change the date format.
NOTE 1:- inputFormatter= the type of format you getting date from api other place
NOTE 2 :- you can change the format according to your getting date
inputFormatter.dateFormat = “yyyy-MM-dd”
2. How you can use this function
In the fig 1, we can see my input date is 2220–12–03 so, my date format is yyyy-MM-dd.
you can change it according your input date.
3. Formats and their output
Down below i mentioned many format and their outputs:
EEEE, MMM d, yyyy
output- Tuesday, Oct 27, 2020
MM/dd/yyyy
output- 10/27/2020
MM-dd-yyyy HH:mm
output- 10–27–2020 06:44
MMM d, h:mm a
output- Oct 27, 6:44 AM
MMMM yyyy
output- October 2020
MMM d, yyyy
output- Oct 27, 2020
E, d MMM yyyy HH:mm:ss Z
output- Tue, 27 Oct 2020 06:44:31 +0000
E, d MMM yyyy HH:mm:ss Z
output- Tue, 27 Oct 2020 06:44:31 +0000
yyyy-MM-dd’T’HH:mm:ssZ
output- 2020–10–27T06:44:31+0000
dd.MM.yy
output- 27.10.20
HH:mm:ss.SSS