• 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: Changing current date format
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing current date format


  • Subject: Re: Changing current date format
  • From: Shane Stanley <email@hidden>
  • Date: Mon, 20 Jan 2014 09:46:56 +1100

On 20 Jan 2014, at 6:51 AM, Christopher Stone <email@hidden> wrote:

One of the nice things about handlers is that you can have a pure mess of spaghetti code in one with a much simpler invocation in the body of your code.

And one of the nice things about script libraries is that you can hide it away. And interleaved syntax can help define more descriptive handler names.

FYI, this is such a lib for date formatting in Mavericks:

use framework "Foundation"

on formatDate:theDate usingFormat:formatString
if class of theDate is date then set theDate to my makeNSDateFrom:theDate
set theFormatter to current application's NSDateFormatter's new()
theFormatter's setDateFormat:formatString
set theString to theFormatter's stringFromDate:theDate
return theString as text
end formatDate:usingFormat:

on makeNSDateFrom:theASDate
set {theYear, theMonth, theDay, theSeconds} to theASDate's {year, month, day, time}
if theYear < 0 then
set theYear to -theYear
set theEra to 0
else
set theEra to 1
end if
set theCalendar to current application's NSCalendar's currentCalendar()
set newDate to theCalendar's dateWithEra:theEra |year|:theYear |month|:(theMonth as integer) ¬
|day|:theDay hour:0 minute:0 |second|:theSeconds nanosecond:0
return newDate
end makeNSDateFrom:

Called by:

use theLib : script "<name of lib>" 
use scripting additions

theLib's formatDate:(current date) usingFormat:"ddMMMYY"
--> "20Jan14"
theLib's formatDate:(current date) usingFormat:"dd MMMM YY"
--> "20 January 14"

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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

References: 
 >Changing current date format (From: JF <email@hidden>)
 >Re: Changing current date format (From: Luther Fuller <email@hidden>)
 >Re: Changing current date format (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: Changing current date format
  • Next by Date: Re: Changing current date format
  • Previous by thread: Re: Changing current date format
  • Next by thread: Re: Changing current date format
  • Index(es):
    • Date
    • Thread