【问题标题】:Google Email Script Changing DateGoogle 电子邮件脚本更改日期
【发布时间】:2018-10-10 09:05:55
【问题描述】:

我正在使用下面的电子邮件发送脚本向获得授权的人发送一些日期,在谷歌表格中其格式化

DD/MM/YYYY

但是发送的是一个很长的日期,像这样附加时间

“2019 年 1 月 7 日星期一 00:00:00 GMT-0000 (GMT)”

我只需要它准确发送单元格中的内容而不更改它,我已经尝试了一些迄今为止没有奏效的东西,我不想更改工作表中的内容,只需发送显示的内容。

任何帮助将不胜感激

脚本是

// Scrips for Email sheet PHC main 
// has been sent successfully.
var EMAIL_SENT = "SENT";

function sendEmailshol() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;  // First row of data to process
  var numRows = 5;   // Number of rows to process
  // Fetch the range of cells 
  var dataRange = sheet.getRange(startRow, 1, numRows, 50) ;  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var emailAddress = row[42] ;  // First column
    var message = 'Hi ' + row[3] + '\n'// Hi then Name from sheet then new line 
    + 'xxx.' + '\n\n' 
    + row[5] + ' To ' + row[6] + ' ' + row[7] + '\n' 
    + '\n\n' 
    + 'Any questions please dont hesitate to give me a call.' + '\n\n' 
    var emailSent = row[43];     // Third column
    if (emailSent != EMAIL_SENT) {  // Prevents sending duplicates
      var subject = 'xxx' ;
      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 44).setValue(EMAIL_SENT);       // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush();
    }
  }
}

【问题讨论】:

    标签: javascript email google-apps-script


    【解决方案1】:

    您可以在这里查看日期格式,https://developers.google.com/google-ads/scripts/docs/features/dates

    Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
    

    所以在你的情况下它会是......

    var formatedDate = Utilities.formatDate(unFormatedDate, yourTimeZone, "DD/MM/YYYY");
    

    希望它会有所帮助:)

    【讨论】:

    • 谢谢你,我已经尝试过了,它给出了这个错误 ReferenceError: "unFormatedDate" is not defined。 (第 7 行,文件“代码”)
    • 是的,您的代码中没有定义“unFormatedDate”,请将 unFormatedDate 更改为您要更改格式的日期。
    猜你喜欢
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 2020-11-24
    • 2015-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多