简体   繁体   中英

Convert Date(JS) object to TimeStamp(firestore) in Google Apps Script

I've got a date object in Google App Script which I want to import to firestore as a timestamp object, but it doesn't work when I do it directly.

This stores an empty map in firestore:

data.date = new Date();

I get this in firestore:

我明白了

But I want this:

在此处输入图像描述

This is my full code:

function uploadData() {
   var firestore = FirestoreApp.getFirestore (email, key, projectId);
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheetname = "Sheet1";
   var sheet = ss.getSheetByName(sheetname); 
   var sheetLR = sheet.getLastRow();
   var sheetLC = sheet.getLastColumn(); 
   var dataSR = 2; 
   var sourceRange = sheet.getRange(2,1,sheetLR-dataSR+1,sheetLC);
   var sourceData = sourceRange.getValues();
   var sourceLen = sourceData.length;

  // Loop through the rows
   for (var i=0;i<sourceLen;i++){
     if(sourceData[i][1] !== '') {
       var data = {};

       var date = sourceData[i][0]; //this is the date object
       data.date = new Date(); //Want to convert this date to timestamp object for firestore
       data.title = sourceData[i][1];

       firestore.createDocument("collection", data);
     }

  }
}

Thanks, this bug has been fixed in the latest version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM