AppleScript名:数値の秒を文字フォーマットして返す |
— Created 2016-02-09 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aStr to formatTimeNum(61) of me –> "01分 01秒" set bStr to formatTimeNum(3700) of me –> "01時間 01分 40秒" set cStr to formatTimeNum(9100) of me –> "02時間 31分 40秒" set dStr to formatTimeNum(720001) of me –>"200時間 00分 01秒" set eStr to formatTimeNum(7200001) of me –>"2000時間 00分 01秒" –数値の秒を文字フォーマットして返す on formatTimeNum(a) set hourStr to "時間 " set minuteStr to "分 " set secStr to "秒" set aRec to separateSec(a) of me set aStr to "" set anHour to hourNum of aRec set aMinute to minuteNum of aRec set aSec to secondNum of aRec if anHour > 0 then set aStr to aStr & retZeroPaddingText(anHour, 2) of me & hourStr set aStr to aStr & retZeroPaddingText(aMinute, 2) of me & minuteStr else if aMinute > 0 then set aStr to aStr & retZeroPaddingText(aMinute, 2) of me & minuteStr end if set aStr to aStr & retZeroPaddingText(aSec, 2) of me & secStr return aStr end formatTimeNum —数値の秒を時、分、秒に分解する on separateSec(a) set anHour to a div 3600 set b to a – (anHour * 3600) set aMinute to b div 60 set c to b – (aMinute * 60) return {hourNum:anHour, minuteNum:aMinute, secondNum:c} end separateSec –ゼロパディング on retZeroPaddingText(aNum as integer, aDigitNum as integer) if aNum > (((10 ^ aDigitNum) as integer) – 1) then return aNum as string –指定桁数を数値データがオーバーしたら数値を文字化してそのまま返す end if set aFormatter to current application’s NSNumberFormatter’s alloc()’s init() aFormatter’s setUsesGroupingSeparator:false aFormatter’s setAllowsFloats:false aFormatter’s setMaximumIntegerDigits:aDigitNum aFormatter’s setMinimumIntegerDigits:aDigitNum aFormatter’s setPaddingCharacter:"0" set aStr to aFormatter’s stringFromNumber:(current application’s NSNumber’s numberWithFloat:aNum) return aStr as string end retZeroPaddingText |
More from my site
(Visited 25 times, 3 visits today)