Class DateField

วันที่ช่อง

เลิกใช้งานแล้ว แต่ให้ใช้บริการขั้นสูงของ People API แทน

ช่องวันที่ในรายชื่อติดต่อ

คลาสนี้ใช้โดยบริการ Contacts เท่านั้น และวันที่ที่ใช้ในที่อื่นๆ ใน App Script จะใช้ออบเจ็กต์ Date มาตรฐานของ JavaScript

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
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()

รับป้ายกำกับของช่องนี้ ซึ่งอาจเป็นฟิลด์ 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 — ป้ายกำกับของช่องนี้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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 มาตรฐาน เมธอด 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