AppleScript名:指定日における年齢を計算する |
— Created 2015-09-10 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –http://stackoverflow.com/questions/4463893/ –how-to-calculate-the-age-based-on-nsdate set aBirthday to "2009-04-24 12:00:00" –誕生日 set aFormatter to current application’s NSDateFormatter’s alloc()’s init() aFormatter’s setDateFormat:"yyyy-MM-dd HH:mm:ss" aFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneForSecondsFromGMT:0) set aBirthdayDate to aFormatter’s dateFromString:aBirthday set currentDate to getDateInternational(2018, 4, 1, 9, 59, 35, "JST") of me set ageComponents to current application’s NSCalendar’s currentCalendar()’s components:(current application’s NSCalendarUnitYear) fromDate:aBirthdayDate toDate:currentDate options:0 set myAge to ageComponents’s |year|() –> 8 –Make a GMT Date Object with parameters from a given time zone. on getDateInternational(aYear, aMonth, aDay, anHour, aMinute, aSecond, timeZoneAbbreviation) set theNSCalendar to current application’s NSCalendar’s currentCalendar() theNSCalendar’s setTimeZone:(current application’s NSTimeZone’s timeZoneWithAbbreviation:(timeZoneAbbreviation)) set theDate to theNSCalendar’s dateWithEra:1 |year|:aYear |month|:aMonth |day|:aDay hour:anHour minute:aMinute |second|:aSecond nanosecond:0 return theDate end getDateInternational |
More from my site
(Visited 40 times, 1 visits today)