0

I use Gloss for parsing JSON. I've got issues with parsing Date fields. My JSON input:

"PurchasedAt": 2016-08-02T17:23:12.000Z,

Struct:

let purchasedAt: Date?

init?(json: JSON) {

    self.purchasedAt = Decoder.decodeDate("PurchasedAt", dateFormatter: LTUtilities.getDateFormatter()) (json)

}


static func getDateFormatter() -> DateFormatter {

        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-dd-MM'T'HH:mm:ss'Z'"
        return dateFormatter
    }

Finally, I keep getting nil value for any Date field. Your help is very appreciated and thank you in advance.

NCFUSN
  • 1,624
  • 4
  • 28
  • 44
  • Hello friend , your problem is related to the format of your time stamp, check my previus answer https://stackoverflow.com/questions/37466837/why-does-it-return-nil-when-i-unwrap-the-array-of-strings-in-localnotification/37467175#37467175, I hope this helps you, if not, then let me know, and I help you – Reinier Melian Oct 19 '16 at 16:30
  • Thank you for your comment. Unfortunately changing the format didn't resolve the issue. – NCFUSN Oct 20 '16 at 08:10
  • Not sure if related to your issue, but I'd bet that "2016-08-02" means "yyyy-MM-dd" and not "yyyy-dd-MM". – Eric Aya Oct 20 '16 at 10:06
  • It's true and and corrected, but still doesn't solve the problem. – NCFUSN Oct 20 '16 at 10:50

1 Answers1

0

Ok guys, solved this issue by myself with

"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSS'Z'"

DateFormatter format string.

NCFUSN
  • 1,624
  • 4
  • 28
  • 44