【问题标题】:adding a timestamp in hh:mm timestamp in googlescript在谷歌脚本中的 hh:mm 时间戳中添加时间戳
【发布时间】:2019-02-21 21:42:58
【问题描述】:

有谁知道如何在脚本运行时将时间戳添加到一个单元格中并采用 hh:mm 格式。

我能得到的最近的是

function RefreshORM(){

 var ss = SpreadsheetApp.getActive()

 ss.getSheetByName('ORM').getRange('D17').clear({contentsOnly: true})
 ss.getSheetByName('ORM').getRange('M21:M120').clear({contentsOnly: true})
 ss.getSheetByName('ORM').getRange('D17').setValue(new Date())

}

但它以 dd/mm/yyyy hh:mm 格式出现,并且不使用公式。

【问题讨论】:

    标签: google-apps-script time timestamp


    【解决方案1】:

    您可以使用Utilities.formatDate(Date,Timezone,Format) 函数格式化new Date() 返回的日期对象,但是您需要确定正确的时区。假设您在一个时区工作,这很简单。

    //assuming your timezone is 'EST'
    
    ss.getSheetByName('ORM').getRange('D17').setValue(Utilities.formatDate(new Date(),'EST','HH:mm'));
    

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

    【讨论】:

    • 太好了,谢谢,我正在查看它们的碎片,但无法使其正常运行。
    猜你喜欢
    • 2021-01-14
    • 2021-02-23
    • 1970-01-01
    • 2023-04-02
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    相关资源
    最近更新 更多