【问题标题】:How do I use the .getMonth() command with Google Contacts in Apps Script?如何在 Apps 脚本中将 .getMonth() 命令与 Google 通讯录一起使用?
【发布时间】:2021-07-29 20:35:27
【问题描述】:

我正在应用程序脚本中编写一些代码,用于加载来自 Google 通讯录的所有联系人,现在我需要获取这些联系人的生日。我已经下载了在 Google Developers Site 上发布的确切代码,但我得到了一个我无法理解的奇怪日志。 它适用于 .getDay() 非常好,然后适用于 .getMonth() 它不起作用。

这是代码:

var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
console.log(birthday.getDay());
console.log(birthday.getMonth());

这是我的日志:

22:22:53    Info    5
22:22:53    Info    Logging output too large. Truncating output. { toString: 
            [Function: toString],
             name: [Function: toString],
           toJSON: [Function: toString],
          ordinal: [Function: ordinal],
        compareTo: [Function: compareTo],
          JANUARY: 
                 { toString: [Function: toString],
                       name: [Function: toString],
              ...
     

任何帮助表示赞赏。我只想输出月数

【问题讨论】:

    标签: google-apps-script google-contacts-api


    【解决方案1】:

    这对我有用

    function getBirthDate1() {
      let bd = ContactsApp.getContactsByName("Bob Katz")[0];
      bd.getDates(ContactsApp.Field.BIRTHDAY).forEach(e => {
        Logger.log(e.getDay());
        Logger.log(e.getMonth());
      });
    }
    
    Execution log
    2:57:10 PM  Notice  Execution started
    2:57:11 PM  Info    1.0
    2:57:11 PM  Info    JANUARY
    2:57:12 PM  Notice  Execution completed
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-06
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      相关资源
      最近更新 更多