格式化Google App脚本中的当前时间

时间:2018-05-01 18:56:54

标签: google-apps-script

如何使用google app脚本设置当前时间?我很难找到时间文档。

我能用毫秒来获得时间。

(new Date()).getTime()

我现在希望将此时间格式化为上午11:56。我正在使用日期documentation。我尝试过使用javascript中的toLocaleTimeString(),但未在应用脚本中定义

1 个答案:

答案 0 :(得分:1)

要格式化日期,您需要的是Utilities.formatDate()函数,在此处记录:https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)

用于获取时间的用法是:

Utilities.formatDate(YOUR DATE,YOUR TIMEZONE, 'HH:mm')

用适当的值替换您的日期和您的时区。

相关问题