date objectをRFC2822 date stringに変換

AppleScript名:date objectをRFC2822 date stringに変換
— Created 2017-12-19 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aDate to getDateInternational(2018, 2, 1) of me
set bStr to rfc2822DateTimeString(aDate, "JST") as string
–>  "Thu, 01 Feb 2018 00:00:00 +0900"

–date -> RFC2822 Date & Time String
on rfc2822DateTimeString(targDate, timeZoneName as string)
  set theNSDateFormatter to current application’s NSDateFormatter’s alloc()’s init()
theNSDateFormatter’s setDateFormat:"EEE, dd MMM yyyy HH:mm:ss Z"
theNSDateFormatter’s setTimeZone:(current application’s NSTimeZone’s alloc()’s initWithName:timeZoneName)
theNSDateFormatter’s setLocale:(current application’s NSLocale’s alloc()’s initWithLocaleIdentifier:"en_US_POSIX")
return (theNSDateFormatter’s stringFromDate:targDate) as text
end rfc2822DateTimeString

–Make Date Object from parameters
on getDateInternational(aYear as integer, aMonth as integer, aDay as integer)
  set theNSCalendar to current application’s NSCalendar’s currentCalendar()
set theDate to theNSCalendar’s dateWithEra:1 |year|:aYear |month|:aMonth |day|:aDay hour:0 minute:0 |second|:0 nanosecond:0
return theDate as date
end getDateInternational

★Click Here to Open This Script 

Please follow and like us:


メールアドレスが公開されることはありません。 * が付いている欄は必須項目です