繁体   English   中英

在Google App脚本中设置当前时间

[英]Format current time in Google App Scripts

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

我可以使用毫秒来获取时间。

(new Date()).getTime()

我现在想将此时间设置为上午11:56。 我正在使用Date 文档 我尝试从JavaScript使用toLocaleTimeString() ,但未在应用脚本中定义

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

仅用于获取时间的用法是:

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

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

暂无
暂无

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

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