Swift reading date incorrectly
问题 I am working on an app where I need to store and read dates. I am finding that Swift will sometimes get the day wrong. var testDate2 = "2016-10-11 17:00:00 +0000" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss Z" let showDate2 = dateFormatter.date(from: testDate2) let calendar = NSCalendar.current let showDate2Components = calendar.dateComponents([.day, .month, .year], from: showDate2!) print (showDate2!) print (showDate2Components.day!) print (showDate2!)