方法
方法 | 返回类型 | 简介 |
---|---|---|
get | Object | 获取此字段的标签。 |
set |
| 设置此字段的标签。 |
已弃用的方法
方法 | 返回类型 | 简介 |
---|---|---|
| void | 删除此日期。 |
| Integer | 获取此日期所在的一月中的第几天。 |
| Month | 获取此日期所在的月份。 |
| Integer | 获取此日期的年份。 |
|
| 将日期设置为今天,不指定年份。 |
|
| 将日期设置为当天。 |
|
| 设置此字段的标签,例如“生日”或“周年纪念”。 |
详细文档
getLabel()
获取此字段的标签。这可以是 Field、ExtendedField 或 String。
// Logs the label for all the address fields associated with contact // 'John Doe'. This method can be similarly called for any field that has // a label. const contacts = ContactsApp.getContactsByName('John Doe'); const addressFields = contacts[0].getAddresses(); for (let i = 0; i < addressFields.length; i++) { Logger.log(addressFields[i].getLabel()); }
返回
Object
- 此字段的标签
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setLabel(label)
设置此字段的标签。
// Sets the label to 'Apartment' for the first address field associated // with contact 'John Doe'. This method can be similarly called for any // field that has a label. const contacts = ContactsApp.getContactsByName('John Doe'); const addressFields = contacts[0].getAddresses(); addressFields[0].setLabel('Apartment');
参数
名称 | 类型 | 说明 |
---|---|---|
label | String | 此字段的新标签 |
返回
- this 字段,适用于链式调用Date
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
已弃用的方法
deleteDateField()
deleteDateField()
已弃用。此函数已废弃,不应在新脚本中使用。
删除此日期。
// Deletes all the dates that are set for contact 'John Doe' const contacts = ContactsApp.getContactsByName('John Doe'); const dates = contacts[0].getDates(); for (let i = 0; i < dates.length; i++) { dates[i].deleteDateField(); }
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
getDay()
getDay()
已弃用。此函数已废弃,不应在新脚本中使用。
获取此日期所在的一月中的第几天。
注意:对于标准 JavaScript Date 对象,
get
方法会改为返回一周中的第几天。
// Logs the day of the birthday for contact 'John Doe' const contacts = ContactsApp.getContactsByName('John Doe'); const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0]; Logger.log(birthday.getDay());
返回
Integer
- 日期
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
getMonth()
getMonth()
已弃用。此函数已废弃,不应在新脚本中使用。
获取此日期所在的月份。
// Logs the month of the birthday for contact 'John Doe' const contacts = ContactsApp.getContactsByName('John Doe'); const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0]; Logger.log(birthday.getMonth());
返回
Month
- 月份
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
getYear()
getYear()
已弃用。此函数已废弃,不应在新脚本中使用。
获取此日期的年份。
// Logs the year of the birthday for contact 'John Doe' const contacts = ContactsApp.getContactsByName('John Doe'); const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0]; Logger.log(birthday.getYear());
返回
Integer
- 年份
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setDate(month, day)
setDate(month, day)
已弃用。此函数已废弃,不应在新脚本中使用。
将日期设置为今天,不指定年份。
此方法仅适用于不需要年份的日期字段,例如生日。
// Sets the birthday for contact 'John Doe' to April 1 const contacts = ContactsApp.getContactsByName('John Doe'); const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0]; birthday.setDate(ContactsApp.Month.APRIL, 1);
参数
名称 | 类型 | 说明 |
---|---|---|
month | Month | 月份 |
day | Integer | 这一天 |
返回
- 此日期,适用于链式调用Date
抛出
Error
- 如果此日期字段需要年份
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setDate(month, day, year)
setDate(month, day, year)
已弃用。此函数已废弃,不应在新脚本中使用。
将日期设置为今天。
// Sets the birthday for contact 'John Doe' to April 1, 1980 const contacts = ContactsApp.getContactsByName('John Doe'); const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0]; birthday.setDate(ContactsApp.Month.APRIL, 1, 1980);
参数
名称 | 类型 | 说明 |
---|---|---|
month | Month | 月份 |
day | Integer | 这一天 |
year | Integer | 年 |
返回
- 此日期,适用于链式调用Date
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setLabel(label)
setLabel(label)
已弃用。此函数已废弃,不应在新脚本中使用。
设置此字段的标签,例如“生日”或“周年纪念”。
// Retrieves the first date that's set for contact 'John Doe' and re-labels // it as an anniversary const contacts = ContactsApp.getContactsByName('John Doe'); const firstDate = contacts[0].getDates()[0]; firstDate.setLabel(ContactsApp.Field.ANNIVERSARY);
参数
名称 | 类型 | 说明 |
---|---|---|
label |
| 新标准标签 |
返回
- this 字段,适用于链式调用Date
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds