Date Format

Hi there,

I need to feed iTunes with a date such as

set d to "28.3.2005"
set t to "16:00:00"
set the_date to date (d & "," & t)
tell application "iTunes"
	set played date of selection to the_date
end tell

The format I’m feeding iTunes is always the same, however because of regional settings months and days are swapped, in this examples if you are under US settings it’s going to spit an error, if you are under French or German it’s happy. What can I do? Do I need to check what the machine’s format is then format accordingly? Which means checking every country (nightmare!)? Can I tell Applescript the format used is DD/MM/YY and not MM/DD//YY?

Any help very much appreciated.

Hi, Michaf.

Just use the bits of your short-date and time strings to set the properties of an AppleScript date. The text-integer coercions are done automatically:

set d to "28.3.2005"
set t to "16:00:00"

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set {dy, m, y} to d's text items
set AppleScript's text item delimiters to ":"
set {h, min, s} to t's text items
set AppleScript's text item delimiters to astid

set the_date to date ("1 1 1" as text) -- 1st January 2001 on any system.
tell the_date to set {its year, its month, its day, its time} to {y, m, dy, h * hours + min * minutes + s} -- Assuming Panther or later.

tell application "iTunes" 
	set played date of selection to the_date 
end tell