Class DateField

日付フィールド

非推奨。代わりに、People API アドバンスト サービスを使用してください。

連絡先の日付フィールド。

このクラスは Contacts サービスでのみ使用されます。App Script の他の場所で使用される日付には、JavaScript の標準の Date オブジェクトが使用されます。

メソッド

メソッド戻り値の型概要
getLabel()Objectこのフィールドのラベルを取得します。
setLabel(label)DateFieldこのフィールドのラベルを設定します。
メソッド戻り値の型概要
deleteDateField()voidこの日付を削除します。
getDay()Integerこの日付の月の曜日を取得します。
getMonth()Monthこの日付の月を取得します。
getYear()Integerこの日付の年を取得します。
setDate(month, day)DateField日付を今日に設定します(年なし)。
setDate(month, day, year)DateField日付を今日に設定します。
setLabel(label)DateFieldこのフィールドのラベル(「誕生日」や「記念日」など)を設定します。

詳細なドキュメント

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 - このフィールドのラベル

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。

  • 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');

パラメータ

名前説明
labelStringこのフィールドの新しいラベル

戻る

DateField - チェーンに便利なフィールド

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。

  • https://www.google.com/m8/feeds

サポート終了のメソッド

非推奨。この関数は非推奨のため、新しいスクリプトでは使用しないでください。

この日付を削除します。

// 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();
}

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。

  • https://www.google.com/m8/feeds

非推奨。この関数は非推奨のため、新しいスクリプトでは使用しないでください。

この日付の月の曜日を取得します。

注: 標準の 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 - 日

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。

  • https://www.google.com/m8/feeds

非推奨。この関数は非推奨のため、新しいスクリプトでは使用しないでください。

この日付の月を取得します。

// 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 - 月

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。

  • https://www.google.com/m8/feeds

非推奨。この関数は非推奨のため、新しいスクリプトでは使用しないでください。

この日付の年を取得します。

// 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 - 年

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。

  • https://www.google.com/m8/feeds

非推奨。この関数は非推奨のため、新しいスクリプトでは使用しないでください。

日付を今日に設定します(年なし)。

この方法は、年を必要としない日付フィールド(誕生日など)にのみ適用されます。

// 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);

パラメータ

名前説明
monthMonth
dayInteger

戻る

DateField - この日付(チェーンに便利)

例外

Error - この日付フィールドに年が必要かどうか

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。

  • https://www.google.com/m8/feeds

非推奨。この関数は非推奨のため、新しいスクリプトでは使用しないでください。

日付を今日に設定します。

// 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);

パラメータ

名前説明
monthMonth
dayInteger
yearInteger

戻る

DateField - この日付(チェーンに便利)

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。

  • https://www.google.com/m8/feeds

非推奨。この関数は非推奨のため、新しいスクリプトでは使用しないでください。

このフィールドのラベル(「誕生日」や「記念日」など)を設定します。

// 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);

パラメータ

名前説明
labelField新しい標準ラベル

戻る

DateField - チェーンに便利なフィールド

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。

  • https://www.google.com/m8/feeds