简体   繁体   中英

How do I use the .getMonth() command with Google Contacts in Apps Script?

I am writing some code in Apps Script that loads all contacts from Google Contacts and now I need to get the birthday for these contacts. I have downloaded the exact code that is published on the Google Developers Site but I am getting a weird log that I cannot comprehend. It works for .getDay() perfectly fine and then with .getMonth() it does not work.

This is the code:

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

This is my log:

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],
              ...
     

Any help appreciated. I just want to output the number of the month

This worked for me

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM