如何使用脚本编辑器在Google电子表格中获取当前时间? [英] How to get the current time in Google spreadsheet using script editor?

查看:170
本文介绍了如何使用脚本编辑器在Google电子表格中获取当前时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个选项可以编写脚本并将其绑定到触发器。问题是,如何在脚本体中获取当前时间?

  function myFunction(){

var currentTime = //<< ???



解决方案

使用JavaScript Date()对象。有很多方法可以从对象中获取时间,日期,时间戳等。 (参考

  function myFunction(){
var d = new Date();
var timeStamp = d.getTime(); // 1970年1月1日以来的毫秒数

// OR:

var currentTime = d.toLocaleTimeString(); //12:35 PM,例如
}


There is an option to write a script and bind it to a trigger. The question is, how to get the current time in the script body?

function myFunction() {

  var currentTime = // <<???

}

解决方案

use the JavaScript Date() object. There are a number of ways to get the time, date, timestamps, etc from the object. (Reference)

function myFunction() {
  var d = new Date();
  var timeStamp = d.getTime();  // Number of ms since Jan 1, 1970

  // OR:

  var currentTime = d.toLocaleTimeString(); // "12:35 PM", for instance
}

这篇关于如何使用脚本编辑器在Google电子表格中获取当前时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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