을 지금까지 선택 다음날으로 시간을 계산,이 코드가 있습니다이 앱은 찾는 어떤 일이의주의와 사용자가
var seconds = 0
var minutes = 0
var hours = 0
var secondsUntilMidnight = 0
var minutesUntilMidnight = 0
var hoursUntilMidnigh = 0
var day = 0
var month = 0
var year = 0
//xvar day = [ hours, minutes, seconds]
var damian = "DayofWeek"
var monday = true
var tuesday = false
var wednesday = true
var thursday = false
var friday = false
var saturday = true
var sunday = false
var currentDay = 0
var nextworkingday = 0
var dayOfTheWeek = [Bool]()///Var collecting bools for each day
var dayOfTheWeekText = [String]()///Collecing name for each day
where the weekday Bool values are adjustable. I want the app to detect the current time and date, and calculate the time until the next day that is set as true.
This is what I have tried so far:
let now = Date()
let calendar = Calendar.current
let components = DateComponents(calendar: calendar, hour:11 , minute : 28) // <- 17:00 = 5pm
// let components2 = DateComponents(calendar: calendar day : 1, _)
let next5pm = calendar.nextDate(after: now, matching: components, matchingPolicy: .nextTime)!
print (now)
let next = calendar.nextDate(after: now, matching: components, matchingPolicy: .nextTime)!
let diff = calendar.dateComponents([.hour, .minute, .second ], from: now, to: next5pm)
///Second time checker
let calendar2 = Calendar.current
let components2 = DateComponents(calendar: calendar2, hour:00 , minute : 00) // <- 17:00 = 5pm
let next1pm = calendar2.nextDate(after: now, matching: components2, matchingPolicy: .nextTime)!
let next2 = calendar2.nextDate(after: now, matching: components2, matchingPolicy: .nextTime)!
let diff2 = calendar2.dateComponents([.hour, .minute, .second ], from: now, to: next1pm)
secondsUntilMidnight = diff2.second!
minutesUntilMidnight = diff2.minute!
hoursUntilMidnigh = diff2.hour!
hours = diff.hour!
minutes = diff.minute!
seconds = diff.second!
을하지만 동안 만 다음 날 일정 시간까지의 시간을 계산 탐지하고 싶습니다. 예를 들어, 오늘이 월요일이고 그 다음날이 수요일 인 경우 그 날의 정해진 시간으로 카운트 다운을 시작합니다.
도움을 주시면 감사하겠습니다. 감사.
업데이트 코드를 무시하십시오. 앱에 필요한 기능을 제공하려고 시도한 것입니다. 이 뷰포트에서 코드가 '오늘'인지 확인하고 그때까지의 시간을 계산하십시오.
다음 번에 [이전 질문] (https://stackoverflow.com/questions/48029814/ios-count-down-until-next-selected-day-in-hours-minutes-seconds) 대신 다음을 수정하십시오. 새 게시. – rmaddy