Re: Date pickers
Re: Date pickers
- Subject: Re: Date pickers
- From: Shane Stanley <email@hidden>
- Date: Tue, 09 Feb 2010 12:20:15 +1100
- Thread-topic: Date pickers
Converting from NSDates to AS dates is problematic, as you probably noticed
from the earlier thread on the subject. You can't just extract a string
version of the date and say "date dateString" as you would in normal AS.
As far as I can see -- and I might well be missing something -- the way to
convert the date/time you see in a date picker to an equivalent AS date is
to make an NSCalendar and use it to extract the various date components from
the NSDate, make an AS date using current date, and then set its various
properties to the values you extracted.
So something like this:
-- assume theNSDate contains an NSDate value
-- make an instance of the current calendar
set theCal to current application's NSCalendar's currentCalendar()
-- build a list of the components we want
set theComponents to ((current application's NSYearCalendarUnit as integer)
¬
+ (current application's NSMonthCalendarUnit as integer) ¬
+ (current application's NSDayCalendarUnit as integer) ¬
+ (current application's NSHourCalendarUnit as integer) ¬
+ (current application's NSMinuteCalendarUnit as integer) ¬
+ (current application's NSSecondCalendarUnit as integer) ¬
)
-- use the calendar to get the components from the date
set theComponents to theCal's components_fromDate_(theComponents, theNSDate)
-- set variables to the various components
tell theComponents
set theYear to |year|()
set theMonth to |month|()
set theDay to |day|()
set theHour to hour()
set theMinute to minute()
set theSecond to |second|()
end tell
-- make an AS date and set the various properties
set theASDate to current date
set year of theASDate to theYear
set month of theASDate to theMonth
set day of theASDate to theDay
set hours of theASDate to theHour
set minutes of theASDate to theMinute
set seconds of theASDate to theSecond
--
Shane Stanley <email@hidden>
AppleScript Pro, April 2010, Florida <http://www.applescriptpro.com>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Date pickers (From: Deivy Petrescu <email@hidden>) |