AppleScriptObjC can only convert between a limited range of classes -- text to NSString, list to NSArray, and so on. Until 10.11 comes out, dates aren't one of the bridgeable classes. One way around that is to use my library: it does the conversion, and quite a bit else besides. But the conversion can also be done with a handler -- the code just becomes a bit longer:
use framework "Foundation"
use scripting additions -- required for 'current date'
on getDatesIn:aString
-- convert string to Cocoa string
set anNSString to current application's NSString's stringWithString:aString
-- create data detector
set theDetector to current application's NSDataDetector's dataDetectorWithTypes:(current application's NSTextCheckingTypeDate) |error|:(missing value)
-- find first match in string; returns an NSTextCheckingResult object
set theMatch to theDetector's firstMatchInString:anNSString options:0 range:{0, anNSString's |length|()}
-- get the date property of the NSTextCheckingResult
set theDate to theMatch's |date|()
return theDate
end getDatesIn:
on makeASDateFrom:theNSDate
set theCalendar to current application's NSCalendar's currentCalendar()
set comps to theCalendar's componentsInTimeZone:(missing value) fromDate:theNSDate -- 'missing value' means current time zone
tell (current date) to set {theASDate, year, day, its month, day, time} to ¬
{it, comps's |year|(), 1, comps's |month|(), comps's |day|(), (comps's hour()) * hours + (comps's minute()) * minutes + (comps's |second|())}
return theASDate
end makeASDateFrom:
set theDate to my getDatesIn:"2015-08-20 15:24:11"
set theASDate to my makeASDateFrom:theDate
and skip both the library and the makeASDateFrom: handler.