0

I have the Layout as below:

LbShowTimeTicking

problem : How to show the time is ticking.

Say I have label LbShowTimeTicking to show : Hour: 10 Min:30 Second:10

The time start ticking until Hrs: 0 Min: 0 , second: 0

func setUpTimer(){

    let date = Date()
    let calendar = Calendar.current    
    let components = calendar.dateComponents([.day,.hour,.minute,.second], from: date as Date)

    let currentDate = calendar.date(from: components)        
    let userCalendar = Calendar.current


    var CountDownDate = DateComponents()

    CountDownDate.year = 2017
    CountDownDate.month = 11
    CountDownDate.day = 10
    CountDownDate.hour = 09
    CountDownDate.minute = 10

    let CountDownDay = userCalendar.date(from: CountDownDate as DateComponents)

    let CountDayDiff = calendar.dateComponents([.day,.hour,.minute,.second], from: currentDate!, to: CountDownDay!)


    let hoursLeft = CountDayDiff.hour
    let minutesLeft = CountDayDiff.minute
    let secondsLeft = CountDayDiff.second

    DispatchQueue.main.async {

        self.Vw_Panel.isHidden = false
        self.lbShowTime.isHidden = false
        self.lbShowTime.text = " Hrs: \(hoursLeft ?? 0),Min:\(minutesLeft ?? 0), Sec:\(secondsLeft ?? 0)"

    }

}

Please help.

Thanks

MilkBottle
  • 4,242
  • 13
  • 64
  • 146

0 Answers0