0

Wrong value recived when decoding date in swift

  let dateFormatterGet = DateFormatter()
    dateFormatterGet.dateFormat = "LLL YYYY"
    dateFormatterGet.timeZone = TimeZone(abbreviation: "UTC")
    dateFormatterGet.locale = Locale(identifier: "en_US_POSIX")
    
    if let date = dateFormatterGet.date(from: "Mar 2020") {
        print(dateFormatterGet.string(from: date))// Prints Dec 2019
print(date)//2019-12-22 00:00:00 +0000

    } else {
       print("There was an error decoding the string")
    }

it prints 2019-12-22 00:00:00 +0000

Amit
  • 556
  • 1
  • 7
  • 24

1 Answers1

1

Should the dateFormat be dateFormatterGet.dateFormat = "LLL yyyy"?

This prints

Mar 2020
2020-03-01 00:00:00 +0000

in my console.

acodeguy
  • 115
  • 1
  • 7