How to get the current system international date format.


Is there a way using applescript to find out the current international date format the user has set?

Thanks in advance.


set chemin to (path to preferences as text) & ".GlobalPreferences.plist"
tell application "Property List Editor" to open file chemin

Look at the item entitled:

Yvan KOENIG (from FRANCE mardi 5 mai 2009 11:57:46)

Hello Yvan

Thank youfor your answer , but unfortunately i get the following error on my 10.4.11 machine (locale: fr_FR) …

	do shell script "defaults read .GlobalPreferences AppleICUDateFormatStrings"
on error e
	return e
end try

(*  result: 
2009-05-05 12:10:12.151 defaults[4503] 
The domain/default pair of (.GlobalPreferences, AppleICUDateFormatStrings) does not exist

	do shell script "defaults read .GlobalPreferences AppleLocale"
on error e
	return e
end try

thanks Yvan that got me going in the right direction - I ended up using the above script to get what I needed.


… this one is shorter

(system info)'s user locale

… but what is the correlation between the ‘system date format’ and the ‘locale’ ?l

… but what is the correlation between the ‘system date format’ and the ‘locale’ ?l

en_US = Month/ Day/ Year USA Default
en_GB - Day/ Month / Year Great Briton UK default

I need this info for a FileMaker DB so I could calculate abbreviated dates correctly.

OK, it’s because I’m using a custom date format which forces the creation of the AppleICUDateFormatStrings

Try to run:

do shell script "defaults read .GlobalPreferences" 

and see if the wanted info is available in the returned stream.

As I use a custom date format I can’t see what is the non-customized stream resembling to.

do shell script "defaults read .GlobalPreferences AppleLocale"

(system info)'s user locale

are doing different tasks.

On my machine, the complete log is:

tell current application
do shell script “defaults read .GlobalPreferences AppleLocale”
system info
{AppleScript version:“1.10.7”, AppleScript Studio version:“1.4.1”, system version:“10.4.11”, short user name:“yyyy”, long user name:“yyyy”, user ID:666, user locale:“fr_FR”, home directory:alias “Macintosh HD:Users:yyyy:”, boot volume:“Macintosh HD”, computer name:“Power Mac G5 de yyyy”, host name:“power-mac-g5-de-yyyy.local”, IPv4 address:“”, primary Ethernet address:“00:00:99:aa:88:aa”, CPU type:“PowerPC 970”, CPU speed:2000, physical memory:4096}
end tell

Isn’t this short handler sufficient to get the wanted info ?

my dateFormat()

on dateFormat()
	local my_birthday, maybe
		set my_birthday to "31/12/1943"
		set maybe to date (my_birthday)
		return "dd/mm/yyyy"
	on error
		return "mm/dd/yyyy"
	end try
end dateFormat

Yvan KOENIG (from FRANCE mardi 5 mai 2009 22:16:41)

Thank you, Yvan, for that very useful little routine. I also used AppleICUDateFormatStrings and wanted to replace that with a more reliable method.

Here’s how I put it to good use:

	This routine takes a date string in Pashua's format
	and returns a date object.
	Useful to get dates from the user through a Pashua interface,
	and use them to create an iCal event.
	Uses a subroutine from Yvan Koenig to get system's date format

property pashuaDate : "2008-12-21 13:09:01 +0200" -- model string from Pashua

set thisDate to pashuaDateToDateObject(pashuaDate)

on pashuaDateToDateObject(pashuaDate)
	local TID, R, dd, mm, yy, rDate, rTime
	set TID to text item delimiters
	set text item delimiters to " "
	set R to text items of pashuaDate -- {"2008-12-21", "13:09:01", "+0200"}
	set text item delimiters to TID
	set {yy, mm, dd} to words of item 1 of R -- {"2008", "12", "21"}
	-- build date string according to system's date setting
	if dateFormat() is "EU" then -- dd-mm-yyyy
		set rDate to dd & "-" & mm & "-" & yy -- "21-12-2008"
	else -- mm-dd-yyyy
		set rDate to mm & "-" & dd & "-" & yy -- "12-21-2008"
	end if
	set rTime to item 2 of R -- "13:09:01"
	set R to date (rDate & " " & rTime) -- date "zondag, 21 december 2008 13:09:01"
	return R
end pashuaDateToDateObject
-- Adapted from routine by Yvan Koenig
-- given date is EU format
-- if no error that's also system's format
on dateFormat()
	local testDate, maybe
		set testDate to "31/12/1943"
		set maybe to date testDate
		return "EU"
	on error
		return "US"
	end try
end dateFormat


you can read the current date format settings also with

word 3 of (do shell script "defaults read AppleTimeResID")
--> e.g. "0" = US


“The domain/default pair of (, AppleTimeResID) does not exist” is what I get.


do shell script "defaults read"
-- result: "{AppleCommandOptionSpace = 0; AppleCommandSpace = 0; }"

So it seems this is also user-dependent, which makes it not really reliable, just like AppleICUDateFormatStrings.

I do have an AppleICUDateFormatStrings key/value pair in my user account.

I guess, if the format settings have never been changed (different from the language settings)
the value must be the same as the current language, the first item in ~/Library/Preferences/.GlobalPreferences.plist > Apple Languages


I realize you can read the locale from:

word 1 of (do shell script "defaults read .GlobalPreferences AppleLocale"

But how do you change that to another locale? The reason I ask, I need to get the current locale, then temporarily change the locale to another country and then reset it back to the original. I presume this is a shell script.


Found it!

do shell script "defaults write -g AppleLocale -string en_UK"  --makes a UK setting