Re: Simple Date-Time Format Question...
Re: Simple Date-Time Format Question...
- Subject: Re: Simple Date-Time Format Question...
- From: kai <email@hidden>
- Date: Wed, 25 Apr 2007 14:02:18 +0100
On Apr 25, 2007, at 2:51 AM, revDAVE wrote:
I would like to set a date-time like:
"4-24-2007 6-41-07 PM"
I don't know how to say it in 'applescript' - something like...?
set date_today to ((the current date) as string)
set theFormat to "mm-dd-yy hh-MM-ss ?m"
Now what?
Bear in mind, Dave, that coercing a date to string (or extracting the
value of its date string and time string properties) will be subject
to local/custom date/time formats. So if you want your script to be
portable, parsing the resulting text may not be such a good idea.
Compare, for example, the following results:
--------------
(current date) as string
--> "Wednesday, April 25, 2007 12:11:10 PM" (United States)
--> "mercredi 25 avril 2007 12:11:10" (France)
--> "Mittwoch, 25. April 2007 12:11:10 Uhr" (Deutschland)
--> "25 de Abril de 2007 12:11:10" (Portugal)
--> "Dé Céadaoin 25 Aibreán 2007 12:11:10" (Éire)
--> "Wednesday, April 25, 2007 12:11:10" (United Kingdom)
--------------
If you merely want the current date in the particular format
described, then a shell approach can take care of most of the
donkeywork:
--------------
do shell script "date +'%m-%d-%Y %I-%M-%S %p'"
--> "04-25-2007 12-11-10 PM" (depending on date/time)
--------------
With regard to a vanilla method for any date, your requirement for a
12-hour clock format means that the answer to this simple question
may not be quite so simple.
The following approach assumes the de facto 12-hour clock convention
(midnight = 12 AM, noon = 12 PM) - rather than that recommended by
the U.S. Government Printing Office Style Manual (the reverse of the
above):
--------------
on |mm-dd-yy hh-MM-ss 12hr format| for d
tell d's hours to tell {" AM", " PM"}'s item (it div 12 + 1) & ¬
(d's year) * 10000 + (d's month) * 100 + (d's day) & ¬
(it + 11) mod 12 * 10000 + 1010000 + (d's minutes) * ¬
100 + (d's seconds) to text 8 thru 9 & "-" & text 10 ¬
thru 11 & "-" & text 4 thru 7 & " " & text 13 thru 14 & ¬
"-" & text 15 thru 16 & "-" & text 17 thru 18 & text 1 thru 3
end |mm-dd-yy hh-MM-ss 12hr format|
set formatted_date to |mm-dd-yy hh-MM-ss 12hr format| for current
date (* or any other date *)
-- do something with formatted_date
--> "04-25-2007 12-11-10 PM" (depending on date/time)
--------------
Or, if you prefer a Unicode version:
--------------
on |mm-dd-yy hh-MM-ss 12hr format| for d
tell d's hours to tell («data utxt33C233D8» as Unicode text)'s ¬
character (it div 12 + 1) & (d's year) * 10000 + (d's month) * ¬
100 + (d's day) & (it + 11) mod 12 * 10000 + 1010000 + ¬
(d's minutes) * 100 + (d's seconds) & " " to text 6 thru 7 & ¬
"-" & text 8 thru 9 & "-" & text 2 thru 5 & " " & text 11 thru 12 & ¬
"-" & text 13 thru 14 & "-" & text 15 thru 17 & character 1
end |mm-dd-yy hh-MM-ss 12hr format|
--------------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden