Lis*_* B. 3 timestamp google-sheets google-apps-script google-forms
我无法在电子表格单元格中获得时间戳格式以包含时间.目前,它只生成日期.我需要更改什么才能获得显示日期和时间的时间戳?
像这样:
3/17/2015 10:57:45
function onEdit(event)
{
var ss = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(r.getColumn() == 8){ //To check if update cell in Column, 1 means first column.
if(r.getValue() == "Resolved"){ //To check the value is equal to Resolved
ss.getRange('L'+r.getRow()).setValue(new Date()); //Set column B1 value to current date.
date = Utilities.formatDate(time, "GMT", "HH:mm:ss");
}else{
ss.getRange('L'+r.getRow()).setValue('');
}
}
Run Code Online (Sandbox Code Playgroud)
在您的代码中,像这样获取脚本的时区:
var timeZone = Session.getScriptTimeZone();
date = Utilities.formatDate(new Date(), timeZone, "MM-dd-yyyy | HH:mm:ss");
Run Code Online (Sandbox Code Playgroud)
你需要使用:
var formattedDate = Utilities.formatDate(time, "GMT", "MM-dd-yyyy HH:mm:ss");
Run Code Online (Sandbox Code Playgroud)
文档中有一个例子:
| 归档时间: |
|
| 查看次数: |
23063 次 |
| 最近记录: |