AppleScript名:ISO8601日付文字列を生成 v2 |
use AppleScript version "2.5" use scripting additions use framework "Foundation" set aDate to getDateInternational(2018, 12, 18, 9, 59, 35, "CET") –―year, month, date, hour, minute, second, time zone abbreviation. set bStr to retISO8601DateTimeString(aDate, "CET") as string –> "2018-12-18T09:59:35+01:00" –NSDate -> ISO8601 Date & Time String on retISO8601DateTimeString(targDate, timeZoneAbbreviation) set theNSDateFormatter to current application’s NSDateFormatter’s alloc()’s init() theNSDateFormatter’s setDateFormat:"yyyy-MM-dd’T’HH:mm:ssZZZZZ" — Five zeds to get a colon in the time offset (except with GMT). theNSDateFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneWithAbbreviation:(timeZoneAbbreviation)) return (theNSDateFormatter’s stringFromDate:targDate) as text end retISO8601DateTimeString –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 as date end getDateInternational |
More from my site
(Visited 60 times, 1 visits today)