現在の日時オブジェクトを取得(AppleScript エディタで実行)
current date
結果
date "2014年8月8日金曜日 7:10:15"
これをつかって現在日時をMySQLの日付書式で取得する処理を書いてみた。
-- 戻り値:文字列(ex. '2014-03-16 10:17:05')
to getCurrentDateString()
set current_date to current date
set val_year to year of current_date
set val_month to month of current_date as number
set val_day to day of current_date
set val_time to time string of current_date
set date_time_string to ""
if val_month < 10 then
set val_month to "0" & val_month as string
end if
if val_day < 10 then
set val_day to "0" & val_day as string
end if
set date_time_string to val_year & "-" & val_month & "-" & val_day & " " & val_time as string
return date_time_string
end getCurrentDateString