我具有此功能,可以计算手机当前分钟的时间。在此特定时间之后,我试图让一个计时器熄灭。该功能的调用方式是通过用户在应用中翻转的开关,并将时间重置为自我。好吧,我遇到了我的NSDATE对象,当开关之前翻转时会获得旧值。有没有办法将NSDATE对象重置为零?
这是我计算手机当前时间的代码。
func GetInitialTime(){
finalTime = 0
firstTimeCounter = 0
timeInSeconds = 0
let calendar = NSCalendar.current
var minutes = calendar.component(.minute, from: date)
var timeDifference = Int()
if(minutes == 00 || minutes == 30) {
print("The minute hand is at zero or thirty.")
}
else {
print("The minute hand is NOT ar zero or thirty")
print("The minute hand ia at:")
if minutes < 30 {
while (!(minutes == 30)) {
minutes += 1
timeDifference += 1
}
print("Therefore we make the minute hand at zero or thiry: ", minutes)
print("The time difference we add to the minute is: ", timeDifference)
}
else {
var i = minutes
while i < 60 {
i += 1
minutes += 1
timeDifference += 1
}
print("Therefore we make the minute hand at zero or thirty: ", minutes)
print("The Time difference we add to the minute is: ", timeDifference)
}
}
finalTime = Double(timeDifference * 60)
print("The time difference in seconds is:", finalTime)
}
,我在此处声明date((对象
let center = UNUserNotificationCenter.current()
let button = UIButton(type: UIButtonType.custom)
let date = Date()
var timeInSeconds = Int()
var finalTime = Double()
var halfHour = Double(1800)
var firstTimeCounter = Int()
var firstTimer = Timer()
var repeatingTimer = Timer()
var backgroundTask = BackgroundTask()
let dispatchGroup = DispatchGroup()
var urlWeb = "http://morrowrenewablesflowdata.com/iOSConnections/Notifications.php"
var downtimes = [String]()
var flows = [String]()
您的代码使用的是一个让常数的实例变量date
。您不会显示设置的上下文,但是我假设它是类的实例变量。这是一个让人常数的事实,意味着它永远不会改变其声明的范围。这几乎可以肯定是您的问题。