簡體   English   中英

如何在獲取過去 email 的日期后格式化日期?

[英]How to format date after getting the date of a past email?

我正在連接一個腳本,從我的 email 中提取 CSV 個文件並將它們移動到驅動器文件夾以便於導入,我想將文件重命名為 email 的日期作為 MMddyyyy,但是,當我在使用 getDate 后格式化日期時(),文件重命名為運行腳本的日期,而不是收到 email 的日期。

//const fileType = ['csv'];
//const processedLabel = "Processed TBD Data";
//var res = GmailApp.search(query);
const dir = DriveApp.getFolderById("<folderID>");
const query = 'has:attachment from:it label:EOD-TBD';
var rmLabel = GmailApp.getUserLabelByName('EOD-TBD');
var newLabel = GmailApp.getUserLabelByName('Processed TBD Data');

function countThreads() { 

  //Find threads within "EOD-TBD" that have an attachment
  var TBD_Threads = GmailApp.search(query);

  for (var m = 0; m < TBD_Threads.length; m++) { //Counts threads
  var threads = TBD_Threads[m].getMessages()
  
  for (var j = 0; j < threads.length; j++) {
    var date = threads[j].getDate()
    var nDate = Utilities.formatDate(new Date(date), "GMT+1", "MM/dd/yyyy")
    Logger.log("Processing Message from: " + nDate)
    var att=threads[j].getAttachments()
    for (var k = 0; k < att.length; k++){
      var attachmentBlob = att[k].copyBlob().setName(nDate);
      //var file = DriveApp.createFile(attachmentBlob);
      var file = dir.createFile(attachmentBlob);

    }
  }
  TBD_Threads[m].removeLabel(rmLabel);
  TBD_Threads[m].addLabel(newLabel);
}
}

在我的一生中,我無法找到如何正確設置日期格式的方法。 如果我記錄“日期”,它會顯示正在處理的 email 的正確日期,但顯示為 [日][編號日][月][年][時間]。

我修好了它。 var nDate = Utilities.formatDate(new Date(date), "GMT+1", "MM/dd/yyyy")var nDate = Utilities.formatDate(date, "GMT-0600", "MM/dd/yyyy")

如果我理解正確,getDate() 使用的時區與 formatDate() 中的時區聲明不同,所以它是今天的日期? 無論哪種方式,一旦我更改了時區以匹配,它就會正確地格式化為 email 的日期。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM