【问题标题】:How to set today's date and time when pressing a button按下按钮时如何设置今天的日期和时间
【发布时间】:2019-08-31 12:56:43
【问题描述】:

我一直在关注这个指南https://www.youtube.com/watch?v=fj3ALXI90-Q

但我希望以另一种方式显示日期和时间。 这就是我按下按钮时想要发生的事情:

8/31/2019 9:49:23

但这就是显示的内容 2019-08-31 14.45.29 我知道它离我想要的不是太远,但它仍然不是我想要的显示方式。这是代码。如果我能得到整个代码,我将不胜感激,因为我缺乏编码知识,所以我可以复制和粘贴。

function setNow() {
  SpreadsheetApp.getActiveRange().setValue(new Date());
}

【问题讨论】:

  • 只需根据您的首选类型格式化列?

标签: google-apps-script google-sheets formatting timestamp


【解决方案1】:

代替:

new Date()

尝试使用:

Utilities.formatDate(time, "GMT+5", "M/d/yyyy, h:mm:ss");

见:https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    相关资源
    最近更新 更多