Linux date命令用于生成电子邮件标头

时间:2018-04-25 00:30:29

标签: bash date

我正在编写一个用于创建电子邮件的bash脚本。

如何使用Linux date命令生成有效的日期标题?

1 个答案:

答案 0 :(得分:2)

电子邮件标题日期类似于Fri, 6 Apr 2018 13:30:00 -0500

使用date命令,这是 date +'%a, %-d %b %Y %H:%M:%S %z'

RFC5322表示该格式的正式规范是:

    date-time       =   [ day-of-week "," ] date time [CFWS]
    day-of-week     =   ([FWS] day-name) / obs-day-of-week
    day-name        =   "Mon" / "Tue" / "Wed" / "Thu" /
                       "Fri" / "Sat" / "Sun"
    date            =   day month year
    day             =   ([FWS] 1*2DIGIT FWS) / obs-day
    month           =   "Jan" / "Feb" / "Mar" / "Apr" /
                       "May" / "Jun" / "Jul" / "Aug" /
                       "Sep" / "Oct" / "Nov" / "Dec"
    year            =   (FWS 4*DIGIT FWS) / obs-year
    time            =   time-of-day zone
    time-of-day     =   hour ":" minute [ ":" second ]
    hour            =   2DIGIT / obs-hour
    minute          =   2DIGIT / obs-minute
    second          =   2DIGIT / obs-second
    zone            =   (FWS ( "+" / "-" ) 4DIGIT) / obs-zone