Class DateField
DateField
已弃用。请改用 People API 高级服务
联系人中的日期字段。
此类仅供通讯录服务使用,而 App 脚本中其他位置使用的日期使用 JavaScript 的标准
Date 对象。
详细文档
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.
var contacts = ContactsApp.getContactsByName('John Doe');
var addressFields = contacts[0].getAddresses();
for (var 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.
var contacts = ContactsApp.getContactsByName('John Doe');
var addressFields = contacts[0].getAddresses();
addressFields[0].setLabel('Apartment');
参数
名称 | 类型 | 说明 |
label | String | 此字段的新标签 |
弃踢回攻
DateField
- 此字段,可用于链接
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
已废弃的方法
deleteDateField()
已弃用。此函数已弃用,不应在新脚本中使用。
删除此日期。
// Deletes all the dates that are set for contact 'John Doe'
var contacts = ContactsApp.getContactsByName('John Doe');
var dates = contacts[0].getDates();
for (var i = 0; i < dates.length; i++) {
dates[i].deleteDateField();
}
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
getDay()
已弃用。此函数已弃用,不应在新脚本中使用。
获取此日期的几号。
注意:对于标准 JavaScript Date 对象,
getDay()
方法会返回星期几。
// Logs the day of the birthday for contact 'John Doe'
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
Logger.log(birthday.getDay());
弃踢回攻
Integer
- 一个月中的某一天
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
getMonth()
已弃用。此函数已弃用,不应在新脚本中使用。
获取此日期对应的月份。
// Logs the month of the birthday for contact 'John Doe'
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
Logger.log(birthday.getMonth());
弃踢回攻
Month
- 月份
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
getYear()
已弃用。此函数已弃用,不应在新脚本中使用。
获取此日期的年份。
// Logs the year of the birthday for contact 'John Doe'
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
Logger.log(birthday.getYear());
弃踢回攻
Integer
- 年份
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setDate(month, day)
已弃用。此函数已弃用,不应在新脚本中使用。
将日期设置为当天(不含年份)。
此方法仅适用于不需要年份的日期字段,例如生日。
// Sets the birthday for contact 'John Doe' to April 1
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
birthday.setDate(ContactsApp.Month.APRIL, 1);
参数
名称 | 类型 | 说明 |
month | Month | 本月 |
day | Integer | 这一天 |
弃踢回攻
DateField
- 此日期,可用于链接
抛出
Error
- 如果此日期字段需要年份
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setDate(month, day, year)
已弃用。此函数已弃用,不应在新脚本中使用。
将日期设为这一天。
// Sets the birthday for contact 'John Doe' to April 1, 1980
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
birthday.setDate(ContactsApp.Month.APRIL, 1, 1980);
参数
名称 | 类型 | 说明 |
month | Month | 本月 |
day | Integer | 这一天 |
year | Integer | 本年 |
弃踢回攻
DateField
- 此日期,可用于链接
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setLabel(label)
已弃用。此函数已弃用,不应在新脚本中使用。
设置此字段的标签,例如“生日”或“周年纪念日”。
// Retrieves the first date that's set for contact 'John Doe' and re-labels
// it as an anniversary
var contacts = ContactsApp.getContactsByName('John Doe');
var firstDate = contacts[0].getDates()[0];
firstDate.setLabel(ContactsApp.Field.ANNIVERSARY);
参数
弃踢回攻
DateField
- 此字段,可用于链接
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2023-12-02。
[]
[]
{
"last_modified": "最后更新时间 (UTC):2023-12-02。",
"state": ""
}