2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AppleScriptで現在日時の文字列を取得する

Posted at

現在の日時オブジェクトを取得(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
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?