1
我想將日期從23 May, 2017
轉換爲23-05-2017
。轉換日期格式返回錯誤日期xcode
我試着用下面的代碼,但它返回25-12-2016
。
NSDateFormatter *oldFormatter = [NSDateFormatter new];
[oldFormatter setDateFormat:@"dd MMM, YYYY"];
NSDate *oldDate = [oldFormatter dateFromString:dateStr];
NSDateFormatter *newFormatter = [NSDateFormatter new];
[newFormatter setDateFormat:@"dd-MM-YYYY"];
我正在使用Xcode 8.2.1。 謝謝。
「YYYY」,而不是 「YYYY」。看到這個:http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns找到原因。 – Larme