2

I am trying to use DatePicker in my app. After I select a date, the displayed text changes randomly. it changes on random dates too. Sometimes it shows date like "Jan 26, 2021" and sometimes it shows "1/28/2021".

Can someone please help me find a solution here ? I want to show something like "Jan 26, 2021" if that date is selected.

Here is how it works right now enter image description here

Here is my code

import SwiftUI

struct WeirdDate: View {
    @State var selectedDate : Date = Date()
    var body: some View {
        VStack {
            Form {
                Text("Testing out Date")
                DatePicker(
                    "Date: ",
                    selection: $selectedDate,
                    displayedComponents: [.date]
                )
            }
        }
    }
}

struct WeirdDate_Previews: PreviewProvider {
    static var previews: some View {
        WeirdDate()
    }
}
ILuvProgramming
  • 121
  • 1
  • 11
  • Can confirm, reproducible in simulator, iOS 14.3, Xcode 12.3. Clearly a bug, worth submitting to Apple. – pawello2222 Jan 27 '21 at 15:02
  • There is a workaround here: https://stackoverflow.com/questions/66090210/swiftui-datepicker-jumps-between-short-and-medium-date-formats-when-changing-the – lorenzo Oct 13 '21 at 16:07

0 Answers0