Skip to content

[SR-16114] Date formatting ignoring iOS user's 24 hour setting #4690

Open
@swift-ci

Description

@swift-ci
Previous ID SR-16114
Radar None
Original Reporter cjmash (JIRA User)
Type Bug
Environment

iOS 15.4, iPhone 13 Pro and iPhone 7

Additional Detail from JIRA
Votes 0
Component/s swift
Labels Bug
Assignee None
Priority Medium

md5: d994803846ed6523cc5965f0000f5224

Issue Description:

Using the following code to format a date to a string doesn't honour the iOS device setting for "24-Hour Time" (under Date & Time settings), it seems to just take whatever the default is for the region, so it changes between 24 hour and 12 hour times for UK and US, but if the user changes from the default "24-Hour Time" setting it sticks with the regions default.

return date.formatted(.dateTime
                       .weekday()
                       .day()
                       .month(.twoDigits)
                       .year()
                       .hour()
                       .minute())

The following behaves correctly:

let formatter = DateFormatter()
formatter.setLocalizedDateFormatFromTemplate("E, dd/MM/yy, j:mm")
return formatter.string(from: date)

I came across this after an Australian user reported that my app was ignoring her 24-Hour Time setting (enabled) and showing AM/PM times instead.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions