0

I want to convert 2021-04-23T07:43:52.532656+00:00 to 04 April, 2021 7:43 Am

I am getting the day month and year correct but I have problems when formatting the time can somebody help me

My problem when converting time - I want the same time but when formatting it goes to the current time zone

func dateFormating(date : String) -> Date{
    
    dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//yyyy-MM-dd'T'HH:mm:ssZ
//  var localTimeZoneAbbreviation: String { return TimeZone.current.abbreviation() ?? "UTC" }
//  dateFormatter.locale = Locale.init(identifier: localTimeZoneAbbreviation)
//  dateFormatter.locale = Locale(identifier: "en_US_POSIX")
    dateFormatter.timeZone = NSTimeZone.local
    return  dateFormatter.date(from: date) ?? Date()
}
func dateConverter(date : Date) -> String {
    print("date in here 1 = \(date)")
    
    let dateFormatterNormal = DateFormatter()
    dateFormatterNormal.dateFormat = date.dateFormatWithSuffix()
//  var localTimeZoneAbbreviation: String { return TimeZone.current.abbreviation() ?? "UTC" }
//  dateFormatterNormal.locale = Locale.init(identifier: localTimeZoneAbbreviation)
//  dateFormatterNormal.locale = Locale(identifier: "en_US_POSIX")
//  dateFormatterNormal.timeZone = TimeZone.current
    let endDate = dateFormatterNormal.string(from: date )
    print("endinf date == \(endDate)")
    return endDate
}

func dateFormatWithSuffix() -> String {
    return " MMM , yyyy h:mm a"
}
Asif Mujtaba
  • 447
  • 6
  • 17

0 Answers0