AppleScript名:UTCTime StringとNSDateの相互変換 |
— Created 2015-02-24 by Shane Stanley — Changed 2015-02-25 By Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" set aStr to retUTCTimeString() –> "2018-02-13T12:40:01.936" set aNSDate to retNSDateFromUTCString(aStr) as date –> date "2018年2月13日火曜日 21:39:43" –Current Date -> UTCTime String on retUTCTimeString() –There is need to get Current Calendar in my Time Zone set aCalendar to current application’s NSCalendar’s currentCalendar() set aTimeZone to (aCalendar’s timeZone) set tDiff to (aTimeZone’s secondsFromGMT()) set theNSDateFormatter to current application’s NSDateFormatter’s alloc()’s init() theNSDateFormatter’s setDateFormat:"yyyy-MM-dd’T’HH:mm:ss.SSS" theNSDateFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneForSecondsFromGMT:tDiff) return (theNSDateFormatter’s stringFromDate:(current application’s NSDate’s |date|())) as text end retUTCTimeString –UTCTime String -> NSDate on retNSDateFromUTCString(aText) set aStr to current application’s NSString’s stringWithString:aText set theNSDateFormatter to current application’s NSDateFormatter’s alloc()’s init() theNSDateFormatter’s setDateFormat:"yyyy-MM-dd’T’HH:mm:ss.SSS" theNSDateFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneForSecondsFromGMT:0) return theNSDateFormatter’s dateFromString:aStr end retNSDateFromUTCString |
More from my site
(Visited 46 times, 1 visits today)