Class DateField
    
    
      
    
    
      
      透過集合功能整理內容
    
    
      
      你可以依據偏好儲存及分類內容。
    
  
  
      
    
  
  
  
  
  
    
  
  
    
    
    
日期欄位
已淘汰。請改用 People API 進階服務
聯絡人中的日期欄位。
這個類別只供聯絡人服務使用,App Scripts 中其他位置使用的日期會使用 JavaScript 的標準 
Date 物件。
 
內容詳盡的說明文件
getLabel()
取得這個欄位的標籤。這可能是欄位、ExtendedField 或字串。
// 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 | 這個欄位的新標籤 | 
回攻員
DateField
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
- 
https://www.google.com/m8/feeds
 
 
已淘汰的方法
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()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
取得這個日期的當月日期。
注意:對於標準 JavaScript Date 物件,
getDay() 方法會改為傳回星期幾。
// 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()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
取得這個日期的月份。
// 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()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
取得此日期的年份。
// 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)
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
將日期設為今天,但不包含年份。
這個方法僅適用於不需要年份的日期欄位,例如生日。
// 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 | 這一天 | 
回攻員
DateField
擲回
Error:如果這個日期欄位需要年份
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
- 
https://www.google.com/m8/feeds
 
 
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 | 年 | 
回攻員
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
const contacts = ContactsApp.getContactsByName('John Doe');
const firstDate = contacts[0].getDates()[0];
firstDate.setLabel(ContactsApp.Field.ANNIVERSARY);
參數
回攻員
DateField
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
- 
https://www.google.com/m8/feeds
 
 
 
  
  
  
    
  
 
  
    
    
      
       
    
    
  
  
  除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
  上次更新時間:2025-07-26 (世界標準時間)。
  
  
  
    
      [null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[],[]]