Class DateField
วันที่ช่อง
เลิกใช้งานแล้ว แต่ให้ใช้บริการขั้นสูงของ People API แทน
ช่องวันที่ในรายชื่อติดต่อ
คลาสนี้ใช้โดยบริการ Contacts เท่านั้น และวันที่ที่ใช้ในที่อื่นๆ ใน App Script จะใช้ออบเจ็กต์
Date มาตรฐานของ JavaScript
เอกสารประกอบโดยละเอียด
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');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
label | String | ป้ายกำกับใหม่สำหรับช่องนี้ |
รีเทิร์น
DateField
— ช่องนี้มีประโยชน์สำหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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();
}
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.google.com/m8/feeds
getDay()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรนำมาใช้ในสคริปต์ใหม่
รับวันของเดือนสำหรับวันที่นี้
หมายเหตุ: สําหรับออบเจ็กต์วันที่ 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
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
— เดือน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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
— ปี
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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
— หากช่องวันที่นี้กำหนดให้ต้องระบุปี
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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
— วันที่นี้ มีประโยชน์สำหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
label | Field
| ป้ายกำกับมาตรฐานใหม่ |
รีเทิร์น
DateField
— ช่องนี้มีประโยชน์สำหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.google.com/m8/feeds
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-12-22 UTC
[null,null,["อัปเดตล่าสุด 2024-12-22 UTC"],[[["**Deprecated:** The `DateField` class is deprecated; use the People API advanced service instead."],["Represents a date field within a Contact, specifically for the Contacts service."],["Offers limited functionality with `getLabel()` and `setLabel()` methods for managing date field labels."],["Previously provided methods for manipulating date values are now deprecated, including `getDay()`, `getMonth()`, `getYear()`, and `setDate()`."],["For general date manipulation in Apps Script, use JavaScript's standard `Date` object."]]],[]]