在打印语句 SwiftUI 上显示 DatePicker hourAndMinute
Posted
技术标签:
【中文标题】在打印语句 SwiftUI 上显示 DatePicker hourAndMinute【英文标题】:Show DatePicker hourAndMinute on print statement SwiftUI 【发布时间】:2020-04-26 23:18:52 【问题描述】:我有以下 DatePicker:
Section(header: Text("Notifications will be triggered only between \(startDay) and \(endDay)"))
DatePicker("Start day", selection: $startDay, displayedComponents: .hourAndMinute)
DatePicker("End day", selection: $endDay, displayedComponents: .hourAndMinute)
如何在字符串插值文本上只显示 hourAndMinute 组件?
谢谢
【问题讨论】:
【参考方案1】:使用 DateFormatter,例如:
var dateFormatter: DateFormatter
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm"
return formatter
Section(header: Text("Notifications will be triggered only between \(dateFormatter.string(from: startDay)) and \(dateFormatter.string(from: endDay))"))
DatePicker("Start day", selection: $startDay, displayedComponents: .hourAndMinute)
DatePicker("End day", selection: $endDay, displayedComponents: .hourAndMinute)
【讨论】:
我不得不将HH:mm
更改为h:mm a
,但其他一切都很好。谢谢以上是关于在打印语句 SwiftUI 上显示 DatePicker hourAndMinute的主要内容,如果未能解决你的问题,请参考以下文章