1
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?

More than 1 year has passed since last update.

GAS UTC → JST変換処理を記載して動かしたが変換されない。

Posted at

概要

GASでスプレットシートで使う関数のUTCからJSTを定義したところなぜか変換が行われなかったので自分なりの解決策を簡単にまとめる。

内容

function jst(utc = "2024/03/11 09:13:00") {
  console.log(utc);
  var jst = Utilities.formatDate(new Date(utc), "Asia/Tokyo", "yyyy/MM/dd HH:mm:ss");
  console.log(jst);
  return jst;
}

これだと下記のように出力される。

12:24:53	お知らせ	実行開始
12:24:53	情報	2024/03/11 09:13:00
12:24:53	情報	2024/03/11 09:13:00
12:24:53	お知らせ	実行完了

GASのスクリプトのタイムゾーンを東京から世界協定時刻に変更する。

utcToJst_-プロジェクトの設定-_Apps_Script.png
utcToJst_-プロジェクトの設定-_Apps_Script.png

再度実行すると下記のように出力されたのでうまく変換できた模様

12:26:07	お知らせ	実行開始
12:26:07	情報	2024/03/11 09:13:00
12:26:07	情報	2024/03/11 18:13:00
12:26:07	お知らせ	実行完了
1
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
1
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?