簡體   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