Last active
February 6, 2017 06:36
-
-
Save shahdhiren/fafd05987cbbcce70e1336098ea234ff to your computer and use it in GitHub Desktop.
Convert Date Format (From-To) Swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func convertDateFormat(from: String, to: String, dateString: String?) -> String? { | |
let fromDateFormatter = DateFormatter() | |
fromDateFormatter.dateFormat = from | |
var formattedDateString: String? = nil | |
if dateString != nil { | |
let formattedDate = fromDateFormatter.date(from: dateString!) | |
if formattedDate != nil { | |
let toDateFormatter = DateFormatter() | |
toDateFormatter.dateFormat = to | |
formattedDateString = toDateFormatter.string(from: formattedDate!) | |
} | |
} | |
return formattedDateString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment