如何在谷歌电子表格中自动添加时间戳 [英] How to automatically add a timestamp in google spreadsheet

查看:61
本文介绍了如何在谷歌电子表格中自动添加时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Google 电子表格中有一张包含 5 个单元格的表格,前 3 个仅包含单词,而后 2 个包含时间,特别是时间戳.

I have a sheet in my Google spreadsheet that contains 5 cells, the first 3 contains only words while the last 2 contains time, specifically a timestamp.

cell 1 = data
cell 2 = data
cell 3 = data
cell 4 = time start
cell 5 = time ended

现在,我想要的是当单元格 1 提供数据时,时间戳将自动出现在单元格 4 中.当单元格 2 和单元格 3 提供数据时,时间戳将成为单元格 5 的新值.

Now, what I want is when cell 1 is supplied with data, a timestamp will automatically appear in cell 4. And when cell 2 and cell 3 is supplied with data, a timestamp will be the new value for cell 5.

我的朋友给我一个代码,应该粘贴在脚本编辑器中:

My friend give me a code, that should pasted in Script editor:

function readRows() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var values = rows.getValues();

for (var i = 0; i <= numRows - 1; i++) {
  var row = values[i];
  Logger.log(row);
 }
};

function onOpen() {
 var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
 var entries = [{
 name : "Read Data",
 functionName : "readRows"
}];
spreadsheet.addMenu("Script Center Menu", entries);
};
function timestamp() {
return new Date()
}

此代码粘贴在 =IF(B6="","",timestamp(B6)) 单元格 4 和此 =IF(D6="","",timestamp(C6&B6)) 在单元格 5 上.在他的示例跟踪器中它的工作.但是当我将它复制到我的时,单元格 4 和单元格 5 中的输出是今天的日期而不是时间.

and this code is pasted in =IF(B6="","",timestamp(B6))cell 4 and this one =IF(D6="","",timestamp(C6&B6)) is on cell 5. in his example tracker its working. But when i copied it to mine, the output in cell 4 and cell 5 is the Date today and not the time.

谁能帮助我?为什么输出的是日期而不是时间?

can anyone help me? why does it output the date and not the time?

推荐答案

可以参考这个教程,如果这有帮助的话.在脚本代码中,更改

You can refer this tutorial, if this helps. In the script code, change

var timestamp_format = "MM-dd-yyyy"; // Timestamp Format.

var timestamp_format = "MM-dd-yyyy hh:mm:ss"; // Timestamp Format.

这应该会对你有所帮助.

This should probably help you.

这篇关于如何在谷歌电子表格中自动添加时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆