需要更改日期格式

Need To Change The Date Format

我需要更改 A 列中的日期格式,我需要在其中获取类似 JULY 21 2020 的内容 但是我在电子邮件正文中收到的内容是这样的 日期 - 2020 年 7 月 23 日星期四 00:00:00 GMT+0530(印度标准时间)

你能帮我更改下面脚本中的日期格式吗

function sendEmail(e) {
    var thisSheet = e.source.getActiveSheet();
    if (thisSheet.getName() !== 'ARTWORK' || e.range.columnStart !== 5 || e.range.rowStart == 1 || e.value !== 'NO-Materials') return;
    var body, headers = thisSheet.getRange(1, 1, 1, 3).getValues()[0],
        thisRow = thisSheet.getRange(e.range.rowStart, 1, 2, 3).getValues()[0],
        ref = thisRow[1]


    recipients = "email@email.com",
        subject = "⚫ Art Work No-Images ► " + ref,
        body = "Require Vehicle images for Social Media Campaign\n\n",
        i = 0;
    while (i < 3) {
        body += headers[i] + ' - ' + thisRow[i] + '\n';
        i++;
    }

    MailApp.sendEmail(recipients, subject, body, { name: "AutoDirect" });
}

在有日期的单元格上应用 getValues() 将 return JavaScript Date 对象。这就是你得到的行为。要根据需要设置日期格式,您有两种选择,具体取决于您是要获取显示格式还是应用不同的格式:

使用 getDisplayValues:

方法 getDisplayValues() return 的值与电子表格中的格式完全相同。如果您想检索与显示格式相同的日期,请使用此选项而不是 getValues()

Returns a two-dimensional array of displayed values, indexed by row, then by column. The values are String objects. The displayed value takes into account date, time and currency formatting, including formats applied automatically by the spreadsheet's locale setting.

使用格式日期:

如果您想应用与电子表格中显示的格式不同的格式,您可以继续使用 getValues(),然后使用 Utilities.formatDate(date, timeZone, format) according to this specification 格式化 returned 日期值.例如:

Utilities.formatDate(new Date(), Session.getScriptTimezone(), "MMMM d yyyy");