Post

Replies

Boosts

Views

Activity

DateFormatter return wrong year
my Date type data is "2024-12-28 15:00:00 +0000" and when I use Date formatter to format date with timezone TimeZone(identifier: "Asia/Seoul"), date formatter return wrong year like below (lldb) po print(date); let formatter = DateFormatter(); formatter.timeZone = TimeZone(identifier: "Asia/Seoul"); formatter.dateFormat = "YYYY-MM-dd"; formatter.string(from: date) 2024-12-28 15:00:00 +0000 "2025-12-29" (lldb) po print(date); let formatter = DateFormatter(); formatter.timeZone = .gmt; formatter.dateFormat = "YYYY-MM-dd"; formatter.string(from: date) 2024-12-28 15:00:00 +0000 "2024-12-28"
2
0
141
1w
DateFormatter doesn't work on certain device
this test fail on the specific device which disabled "Date & Time -> 24-Hour Time" and location is Japan, and when I set the locale, it runs fine on that specific device to, and I am curious what makes this happen, so anybody know the reason please help import XCTest final class DateFormatterTest: XCTestCase { func testDateFormatter() throws { let sendTime = "2023-04-25T02:07:29" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss" // dateFormatter.locale = Locale(identifier: "en_US_POSIX") // test fail until I set locale let result = dateFormatter.date(from: sendTime) XCTAssertNotNil(result) } }
3
1
840
Apr ’23