AppleScript 倒计时
AppleScript countdown
我想要一个从当前时间到闹钟时间倒计时的字符串。
我想出了如何获取当前时间以及如何设置闹钟时间。
我遇到的问题是,当我获取当前时间 - 闹钟时间时,它会给我一个数字 然后我需要重新格式化为 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
更新:
swift 你有 % 可以使用
countDownTime = (formatterInteger - timeControlInteger)
let interval = Int(countDownTime)
let seconds = interval % 60
let minutes = (interval / 60) % 60
let hours = (interval / 3600)
但是你如何在 applescript 中做到这一点?
第二个问题的答案:
is there a way to format strings like in swift? like
String(format:"%02d",absHour) – Mathias Halén
是的,但您需要使用 Satimage.osax 脚本附加功能,可在以下位置免费获得:
Satimage AppleScript Additions
Satimage strftime() -- Date/Time Format Function
strftime v : format a date using a specification string like in the C
function strftime.
strftime date or list of date
into string : the formatting string. To obtain ISO 8601 dates, use
"%FT%TZ" or "%GW%V-%uT%TZ" (using the 'with GMT' parameter)
[GMT boolean] : if true, output date as GMT. Default: false, the ouput
date is local.
→ string : the formatted date
EXAMPLE: strftime (current date) into “%x” RETURNS: 07/22/14
"%a, %b %d, %Y" RETURNS: Tue, Jul 22, 2014
set d to current date
-- some ISO 8601 formats:
strftime d into "%FT%T%z"
-- "2007-01-15T16:10:56+0100"
strftime d into "%GW%V-%uT%T%z"
-- "2007W03-1T16:10:56+0100"
--if you need to store the date d as UTC:
strftime d into "%FT%TZ" with GMT
-- "2007-01-15T15:10:56Z"
strftime d into "%a, %b %d, %Y %H:%M:%S %z"
-- "Mon, Jan 15, 2007 16:10:56 +0100"
我想要一个从当前时间到闹钟时间倒计时的字符串。
我想出了如何获取当前时间以及如何设置闹钟时间。
我遇到的问题是,当我获取当前时间 - 闹钟时间时,它会给我一个数字 然后我需要重新格式化为 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
更新: swift 你有 % 可以使用
countDownTime = (formatterInteger - timeControlInteger)
let interval = Int(countDownTime)
let seconds = interval % 60
let minutes = (interval / 60) % 60
let hours = (interval / 3600)
但是你如何在 applescript 中做到这一点?
第二个问题的答案:
is there a way to format strings like in swift? like String(format:"%02d",absHour) – Mathias Halén
是的,但您需要使用 Satimage.osax 脚本附加功能,可在以下位置免费获得: Satimage AppleScript Additions
Satimage strftime() -- Date/Time Format Function
strftime v : format a date using a specification string like in the C function strftime.
strftime date or list of date
into string : the formatting string. To obtain ISO 8601 dates, use "%FT%TZ" or "%GW%V-%uT%TZ" (using the 'with GMT' parameter)
[GMT boolean] : if true, output date as GMT. Default: false, the ouput date is local.
→ string : the formatted date
EXAMPLE: strftime (current date) into “%x” RETURNS: 07/22/14
"%a, %b %d, %Y" RETURNS: Tue, Jul 22, 2014
set d to current date
-- some ISO 8601 formats:
strftime d into "%FT%T%z"
-- "2007-01-15T16:10:56+0100"
strftime d into "%GW%V-%uT%T%z"
-- "2007W03-1T16:10:56+0100"
--if you need to store the date d as UTC:
strftime d into "%FT%TZ" with GMT
-- "2007-01-15T15:10:56Z"
strftime d into "%a, %b %d, %Y %H:%M:%S %z"
-- "Mon, Jan 15, 2007 16:10:56 +0100"