• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple Date-Time Format Question...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple Date-Time Format Question...


  • Subject: Re: Simple Date-Time Format Question...
  • From: "Mark J. Reed" <email@hidden>
  • Date: Wed, 25 Apr 2007 09:22:16 -0400

Total tangent here, but ... The UK date comes out "April 25"?  I
thought that was an Americanism and the UK form was "25 April".



On 4/25/07, kai <email@hidden> wrote:

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



--
Mark J. Reed <email@hidden>
 _______________________________________________
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

  • Follow-Ups:
    • Re: Simple Date-Time Format Question...
      • From: kai <email@hidden>
References: 
 >Simple Date-Time Format Question... (From: revDAVE <email@hidden>)
 >Re: Simple Date-Time Format Question... (From: kai <email@hidden>)

  • Prev by Date: Re: Simple Date-Time Format Question...
  • Next by Date: Re: Shell script does not run
  • Previous by thread: Re: Simple Date-Time Format Question...
  • Next by thread: Re: Simple Date-Time Format Question...
  • Index(es):
    • Date
    • Thread