LoginSignup
1
0

【GAS】日時の変換方法

Posted at

はじめに

弊社ではGAS(Google Apps Script)を使用して色々と自動化しているのですが、暫く触っていないと日時の変換方法など忘れてしまうことがあるので、備忘録的にまとめておこうと思います。

String→Date

文字列からDateに変換する際は以下方法で可能です。

const dateStr = '2022/12/31 12:34:56';
const date = Utilities.parseDate(str, 'JST', 'yyyy/MM/dd HH:mm:ss')

文字列からの変換方法は以上です。

Date→String

Dateから文字列に変換する方法は以下になります。

var today = new Date();
var todayStr = Utilities.formatDate(today, 'JST', 'yyyy-MM-dd HH:mm:ss');

Dateからの変換方法は以上です。

さいごに

たまに触るくらいだと時折忘れるので、こういうのもまとめておくと便利ですね。

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