简体   繁体   English

Apps脚本:时间戳未正确复制

[英]Apps Script : Timestamp is not copying properly

When I am copying timestamp from one sheet to another or in the same sheet only then it is not copying the time from the timestamp. 当我仅将时间戳从一个工作表复制到另一工作表或在同一工作表中时,则不是在复制时间戳的时间。 It is only copying date. 这只是复制日期。 See the below image - 见下图-

在此处输入图片说明

Here is my code - 这是我的代码-

function myFunction() {

  var files = DriveApp.getFilesByName('myfile');
  while (files.hasNext()) {
  var file = files.next();
  var ss = SpreadsheetApp.open(file); 
  var sheet = ss.getSheets()[0];
  var lastRow = sheet.getLastRow();

  var range = sheet.getRange(1,1,lastRow,2);
  var values = range.getValues();

  Logger.log(values);

  var range = sheet.getRange(sheet.getLastRow()+1,1,lastRow, 2);
  range.setValues(values); 
  }
}

The logger contains this information - 记录器包含此信息-

[18-10-20 11:18:17:743 PDT] [[TIMESTAMP, EVENT], [Mon Oct 01 05:10:13 GMT+05:30 2018, Event 1], [Mon Oct 01 05:10:16 GMT+05:30 2018, Event 2], [Mon Oct 01 05:10:17 GMT+05:30 2018, Event 3], [Mon Oct 01 05:10:24 GMT+05:30 2018, Event 4], [Mon Oct 01 05:10:26 GMT+05:30 2018, Event 5], [Mon Oct 01 05:10:32 GMT+05:30 2018, Event 6], [Mon Oct 01 05:10:38 GMT+05:30 2018, Event 7], [Mon Oct 01 05:10:38 GMT+05:30 2018, Event 8], [Mon Oct 01 05:10:45 GMT+05:30 2018, Event 9], [Mon Oct 01 05:11:07 GMT+05:30 2018, Event 10]]

What could be the reason? 可能是什么原因?

Ok. 好。 Answering my own question because I found the answer before someone answered. 回答我自己的问题,因为我在有人回答之前找到了答案。 Just add this formatting code at the bottom to change the format of that cell to your specified format as suggested by TheMaster 只需在底部添加此格式代码,即可将该单元格的格式更改为TheMaster建议的指定格式

sheet.getRange("A:A").activate();
sheet.getActiveRangeList().setNumberFormat('M/d/yyyy H:mm:ss');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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