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

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

问题描述

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

单元格1 =数据

单元格2 =数据

单元格3 =数据

单元格4 =时间开始单元格5 =时间结束



现在,我想要的是当单元格1提供数据时,时间戳将自动出现在单元格4中。而当单元格2和单元格3提供了数据时,时间戳将

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

  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(脚本中心菜单,条目);
};
函数timestamp(){
return new Date()
}



<这个代码被粘贴在 = IF(B6 =,,timestamp(B6))单元格4中,这个 = IF (D6 =,,时间戳(C6和B6))位于单元格5中。但是,当我将它复制到我的,单元格4和单元格5的输出是今天的日期,而不是时间。



任何人都可以帮助我吗?为什么它输出日期而不是时间? .internetgeeks.org / tech / add-timestamp-time-stamp-google-docs-spreadsheet /rel =noreferrer> tutorial ,如果有帮助的话。
在脚本代码中,更改

  var timestamp_format =MM-dd-yyyy; //时间戳格式。 

  var timestamp_format =MM-dd-yyyy hh:mm:ss; //时间戳格式。 

这应该可以帮到你。


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

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);
 }
};

And

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

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.

to

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

This should probably help you.

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

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