首页 文章

如何向Google App Maker添加日期和时间?

提问于
浏览
-1

有人可以帮助我,我想在不需要用户插入的情况下为应用添加时间和日期 . 我已经弄清楚如何修复日期,但不是时间 . 谁能帮我 ?

1 回答

  • 0

    在页面刷新时自动加载文本小部件

    好吧,我对appmaker有点新意,所以这不一定是最简单的方法 . 但这很有效 . 我在屏幕上添加了一个名为todaysDate的新文本小部件,如下所示:

    enter image description here

    然后我进入了客户端脚本并将此代码添加到ready函数中 .

    $(function(){
      google.script.run
        .withSuccessHandler(upDateToDaysDate)
        .getTodaysDate();//this code
    
      google.script.run
        .withSuccessHandler(upDateLastRecipient)
        .getLastEmailRecipient();//this was already there
    });
    

    我在它上面添加了这个函数,因为它似乎必须在使用之前定义函数 .

    function upDateToDaysDate(s){
      app.pages.Email.descendants.TodaysDate.value=s;
    }
    

    然后在服务器脚本中我添加了这个函数:

    function getTodaysDate(){
      return Utilities.formatDate(new Date(),Session.getScriptTimeZone(),"E MMM d, yyyy");//for time just add HH:mm:ss to the format parameter
    }
    

    当您加载页面或预览时,ready函数将调用服务器脚本,它将返回今天的日期,upDateTodaysDate()将把它加载到todaysDate文本小部件中 .

相关问题