swiftUI零基礎(chǔ)學(xué)習(xí) 制作ios日歷基礎(chǔ)知識

代碼
import SwiftUI
struct ContentView: View {
??var body: some View {
????VStack {
??????Text("\(Date())").padding()
??????Text(Date().formatted(Date.FormatStyle().year().day().month()))
??????Text(Date().formatted(date: ?.abbreviated, time: .complete))
??????Button{
????????var current=Calendar.current
????????let toDaystart=current.startOfDay(for: Date())
????????print("todaystart",toDaystart)
????????let tommorrowStart=current.date(byAdding: .day, value: 1, to: toDaystart) ?? Date()
????????print("tommorrowStart",tommorrowStart)
??????}label:{
????????Text("初始時間")
??????}
??????Button{
????????let now=Date()
????????var matchingComponents=DateComponents()
????????matchingComponents.weekday=2
????????let comingDay=Calendar.current.nextDate(after: now, matching: matchingComponents, matchingPolicy: .nextTime) ?? Date()
????????print("comingDay",comingDay)
?????????
?????????
??????}label: {
????????Text("日期匹配")
??????}
?????????
????}
??}
}
struct ContentView_Previews: PreviewProvider {
??static var previews: some View {
????ContentView()
??}
}
效果