Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌应用程序脚本-->;将数字长度转换为日期格式(例如2015-12-02T16:51:31+;00:00)_Javascript_Google Apps Script - Fatal编程技术网

Javascript 谷歌应用程序脚本-->;将数字长度转换为日期格式(例如2015-12-02T16:51:31+;00:00)

Javascript 谷歌应用程序脚本-->;将数字长度转换为日期格式(例如2015-12-02T16:51:31+;00:00),javascript,google-apps-script,Javascript,Google Apps Script,我是谷歌应用程序脚本的新手。我正在使用Mongodb/Realm服务。如何将数字长的数字(例如1436815400277)转换为日期格式(例如2015-12-02T16:51:31+00:00)?谢谢如果我先弄清楚的话,我会继续研究的 函数importMongoDBData(){ const sheet1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“sheet1”) const getData=UrlFetchApp.fetch(

我是谷歌应用程序脚本的新手。我正在使用Mongodb/Realm服务。如何将数字长的数字(例如1436815400277)转换为日期格式(例如2015-12-02T16:51:31+00:00)?谢谢如果我先弄清楚的话,我会继续研究的

函数importMongoDBData(){
const sheet1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“sheet1”)
const getData=UrlFetchApp.fetch('https://....“).getContentText()
const jsonObj=JSON.parse(getData)

对于(让i=0;i从我所看到的来看,numberLong是自1970年1月1日以来的毫秒数,因此我将基于此给出我的答案

在javascript中,如果您最终使用函数
newdate(input_number);
您应该从输入中获得一个格式化的日期

因此,您的代码看起来如下所示:

function importMongoDBData() {

  const sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1")
  const getData = UrlFetchApp.fetch('https://....').getContentText()
  const jsonObj = JSON.parse(getData)
  for(let i=0;i<5;i++){
     sheet1.getRange(i+2, 1).setValue(new date(jsonObj[i].createdAt.$date.$numberLong))
  }
}
函数importMongoDBData(){
const sheet1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“sheet1”)
const getData=UrlFetchApp.fetch('https://....“).getContentText()
const jsonObj=JSON.parse(getData)

对于(让i=0;i从我所看到的来看,numberLong是自1970年1月1日以来的毫秒数,因此我将基于此给出我的答案

在javascript中,如果您最终使用函数
newdate(input_number);
您应该从输入中获得一个格式化的日期

因此,您的代码看起来如下所示:

function importMongoDBData() {

  const sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1")
  const getData = UrlFetchApp.fetch('https://....').getContentText()
  const jsonObj = JSON.parse(getData)
  for(let i=0;i<5;i++){
     sheet1.getRange(i+2, 1).setValue(new date(jsonObj[i].createdAt.$date.$numberLong))
  }
}
函数importMongoDBData(){
const sheet1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“sheet1”)
const getData=UrlFetchApp.fetch('https://....“).getContentText()
const jsonObj=JSON.parse(getData)
对于(设i=0;i使用,您将能够将日期调整为所需的日期格式和时区。此外,只需将毫秒数插入Javascript构造函数,它将自动将其转换为供链接文档中所述的
Utilities.formatDate()
使用

JavaScript日期基本上指定为自UTC 1970年1月1日午夜以来经过的毫秒数

函数importMongoDBData(){
const sheet1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“sheet1”)
const getData=UrlFetchApp.fetch('https://....“).getContentText()
const jsonObj=JSON.parse(getData)
对于(设i=0;i使用,您将能够将日期调整为所需的日期格式和时区。此外,只需将毫秒数插入Javascript构造函数,它将自动将其转换为供链接文档中所述的
Utilities.formatDate()
使用

JavaScript日期基本上指定为自UTC 1970年1月1日午夜以来经过的毫秒数

函数importMongoDBData(){
const sheet1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“sheet1”)
const getData=UrlFetchApp.fetch('https://....“).getContentText()
const jsonObj=JSON.parse(getData)

对于(让i=0;i您将获得一个日期,但我不认为它会被格式化。我认为toISOString()与他们想要的非常接近。但如果这不起作用,您可以始终使用实用程序。formatDate()您将获得一个日期,但我认为它不会被格式化。toISOString()我认为这与他们想要的非常接近。但是如果这不起作用,你可以使用实用程序。formatDate()