Прежде всего, чтобы избежать путаницы в терминологии (rich text
вместо text
), переместите код, чтобы создать строку даты в обработчике.
Чтобы получить 4
из month
, просто приведите его к integer
, затем приведите все компоненты к text
. Чтобы убрать 20
из года, используйте только последние два символа.
tell application "Mail"
repeat with aMessage in messages of inbox
set sSender to (get aMessage's sender)
set sDate to my dateString(date received of aMessage)
end repeat
end tell
on dateString(theDate)
tell theDate to set {yr, mn, dy} to {year as text, its month as integer as text, day as text}
return mn & "/" & dy & "/" & text -2 thru -1 of yr -- 4/27/18
end dateString
Если вы хотите добавить начальные нули к компонентам дня и месяца, используйте другой обработчик для заполнения значений
on dateString(theDate)
tell theDate to set {yr, mn, dy} to {year as text, its month as integer as text, day as text}
return pad(mn) & "/" & pad(dy) & "/" & text -2 thru -1 of yr -- 04/27/18
end dateString
on pad(v)
return text -2 thru -1 of ("0" & v)
end pad