我想要一個從當前時間倒數到鬧鐘時間的字符串。AppleScript倒計時
我已經設法弄清楚如何獲取當前時間以及如何設置鬧鐘時間。
我遇到的問題是,當我將當前時間 - 鬧鐘時間給了我一個數字女巫,然後我需要格式化回hh:mm:ss字符串。
我有這個。
set alarmHour to 23
set alarmMinute to 00
set theDate to the current date
set the hours of theDate to alarmHour
set the minutes of theDate to alarmMinute
set the seconds of theDate to 0
theDate
set countdown to theDate - (current date)
set ss to countdown/60
在這一點上給了我22.283333333333巫婆我現在需要轉換爲HH:MM:SS,然後把它們變成給我00:22:00
更新刺痛: 在迅速,你有%你可以使用
countDownTime = (formatterInteger - timeControlInteger)
let interval = Int(countDownTime)
let seconds = interval % 60
let minutes = (interval/60) % 60
let hours = (interval/3600)
但你怎麼做到這一點在蘋果?
在AppleScript的整數除法忽略其餘('/')是'div',模運算符'%'是'mod' – vadian
有沒有一種方法可以像swift一樣格式化字符串?像String(格式:「%02d」,absHour) –
簡短回答:不可以。您必須「手動」執行所有操作。 AppleScript是一種腳本而不是編程語言。 – vadian