Created
April 17, 2023 11:26
-
-
Save naosim/eb0e897561cdc370fd3d900632a84c32 to your computer and use it in GitHub Desktop.
Googleカレンダーの予定取得
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exportCalendarEvents() { | |
// カレンダーIDを入力してください | |
var calendarId = "primary"; | |
// フォーマット | |
var format = "yyyy/MM/dd HH:mm:ss"; | |
// 今日の日付を取得 | |
var today = new Date(); | |
// 今日の0時0分0秒を計算 | |
var startOfDay = new Date(today.getFullYear(), today.getMonth(), today.getDate()); | |
// 今日の23時59分59秒を計算 | |
var endOfDay = new Date(startOfDay.getTime() + 24 * 60 * 60 * 1000 - 1); | |
// カレンダーの予定を取得 | |
var events = CalendarApp.getCalendarById(calendarId).getEvents(startOfDay, endOfDay); | |
// テキストフォーマットで出力 | |
var output = "開始日時,終了日時,件名\n"; | |
for (var i = 0; i < events.length; i++) { | |
var event = events[i]; | |
var startTime = Utilities.formatDate(event.getStartTime(), Session.getScriptTimeZone(), format); | |
var endTime = Utilities.formatDate(event.getEndTime(), Session.getScriptTimeZone(), format); | |
var title = event.getTitle(); | |
output += startTime + "," + endTime + "," + title + "\n"; | |
} | |
Logger.log(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment