Skip to content

Instantly share code, notes, and snippets.

@naosim
Created April 17, 2023 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naosim/eb0e897561cdc370fd3d900632a84c32 to your computer and use it in GitHub Desktop.
Save naosim/eb0e897561cdc370fd3d900632a84c32 to your computer and use it in GitHub Desktop.
Googleカレンダーの予定取得
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