繁体   English   中英

时间戳日期和时间格式 - Apps 脚本 - 格式日期和时间

[英]Timestamp Date & Time Format - Apps Script - Format Date and Time

我无法在电子表格单元格中获取时间戳格式以包含时间。 目前,它只生成日期。 我需要更改什么才能让时间戳显示日期和时间?

像这样:

2015/3/17 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('');
    }
  }

您需要使用:

var formattedDate = Utilities.formatDate(time, "GMT", "MM-dd-yyyy HH:mm:ss");

文档中有一个例子:

Google 文档 - formatDate

在您的代码中,像这样获取脚本的时区:

var timeZone = Session.getScriptTimeZone();
date = Utilities.formatDate(new Date(), timeZone, "MM-dd-yyyy | HH:mm:ss");

暂无
暂无

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

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