Date Format in Swift

You have to declare 2 different NSDateFormatters, the first to convert the string to a NSDate and the second to print the date in your format.Try this code: Swift 3 and higher: From Swift 3 NSDate class has been changed to Date and NSDateFormatter to DateFormatter.

How do you create a Swift Date object?

Swift has its own Date type. No need to use NSDate. Creating a Date and Time in Swift In Swift, dates and times are stored in a 64-bit floating point number measuring the number of seconds since the reference date of January 1, 2001 at 00:00:00 UTC. This is expressed in the Date structure. The following would give you the current … Read more