0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[GAS] カレンダーを登録する。(色分け、説明なども)

Last updated at Posted at 2025-01-31

やりたいこと

GASでGoogleカレンダーに予定を登録したい
その際に、色分けや説明も追加したい

完成コード

function testCalendar(){
  var cal = CalendarApp.getDefaultCalendar(); // デフォルトアカウントのGoogleカレンダーを取得
  var title = "テストタイトル"; //タイトル
  var startTime = new Date("2024/07/10 12:00"); // 開始日時
  var endTime = new Date("2024/07/10 15:00"); // 終了日時
  cal.createEvent(title, startTime, endTime)
    .setColor(6)  // 色を指定する
    .setDescription('説明テスト'); // カレンダーに登録する。
}

setColor()

値 色
1 パールブルー
2 パールグリーン
3 Mauve
4 パールレッド
5 イエロー
6 オレンジ
7 シアン
8 グレイ
9 ブルー
10 グリーン
11 レッド

躓いたこと

var calendar = CalendarApp.getDefaultCalendar();
calendar.createEvent('New Event',
                        new Date('2024-07-10T10:00:00Z'),
                        new Date('2024-07-10T11:00:00Z'));

とあるサイトで説明のあった上のコードを実行したが、登録されたカレンダーは9時間後だった
上の場合、カレンダーには19:00から20:00の予定となってしまう
概ねタイムゾーンの問題だとは思う

こちらのサイトで紹介のある確認方法で確認したが、正しく日本時間になっていた為、別の方法を模索して上の完成コードができた

参考にしたサイト

Google Apps Script(GAS)からGoogleカレンダーイベントを登録・削除する方法
https://qiita.com/park3taro/items/e33d3bd5381e8ebc6225

Google Apps 公式リファレンス
https://developers.google.com/apps-script/reference/calendar?hl=ja

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?