GameSprit

自転車やMac・AppleScript、映画・小説やドラマのレビュー、備忘メモ・クイズなどを置いています。

AppleScript: 日時・時刻情報を得る -別設計版-2

2009-09-08 21:14:37 | AppleScript
AppleScript: 日時・時刻情報を得る -別設計版 - GameSprit で、yyyymmddhhmmss 形式の日時・時刻情報を得るスプリプトを作ったのですが、またその改良版です。

改良のポイントは、月・日・時・分・秒が1桁のときに、「0」を付けるようにしました。
yyyymmddhhmmss 形式に桁数が揃うわけです。







display dialog my getTimeStamp()

on getTimeStamp()
set localdate to (current date)
set y to year of localdate as number
set m to month of localdate as number
set d to day of localdate as number
set h to hours of localdate as number
set mi to minutes of localdate as number
set ss to seconds of localdate as number

if (count characters of (m as text)) is 1 then set m to "0" & (m as text)
if (count characters of (d as text)) is 1 then set d to "0" & (d as text)
if (count characters of (h as text)) is 1 then set h to "0" & (h as text)
if (count characters of (mi as text)) is 1 then set mi to "0" & (mi as text)
if (count characters of (ss as text)) is 1 then set ss to "0" & (ss as text)

set msg to y & m & d & h & mi & ss
return msg as text
end getTimeStamp

-- Snow Leopard, Mac OS X 10.6


最新の画像もっと見る

post a comment

ブログ作成者から承認されるまでコメントは反映されません。