I\'m trying to format a date from a string into another format.
For example: 2012-05-29 23:55:52 into 29/05 *newline* 2010.
I just
Please find following code to convert date from one format to another format. It will give time in your current zone.
func convertDateFormat(sourceString : String, sourceFormat : String, destinationFormat : String) -> String{
let dateFormatter = DateFormatter();
dateFormatter.dateFormat = sourceFormat;
if let date = dateFormatter.date(from: sourceString){
dateFormatter.dateFormat = destinationFormat;
return dateFormatter.string(from: date)
}else{
return ""
}
}