Skip to content

Instantly share code, notes, and snippets.

@zaki-lknr
Last active April 9, 2021 01:14
Show Gist options
  • Save zaki-lknr/14a160ddabf9d85e2bf6cceee506e7c8 to your computer and use it in GitHub Desktop.
Save zaki-lknr/14a160ddabf9d85e2bf6cceee506e7c8 to your computer and use it in GitHub Desktop.
JavaScriptメモ

JavaScriptメモ

現在日時でオブジェクト作成

let today = new Date();

年月日などの要素取得

メソッド 内容
getFullYear() 西暦(4桁)
getMonth() 月(0オリジン)
getDate()
getHours()
getMinutes()
getSeconds()
getDay() 曜日(日曜0)

昨日

todayに対して日付を-1する。

  let today = new Date();
  let yesterday = new Date();
  yesterday.setDate(today.getDate() - 1);

指定日

文字列指定

let d = new Date('2021-01-01');

new date: Fri Jan 01 2021 09:00:00 GMT+0900 (Japan Standard Time) 意外といけた。

リンクテキスト

setValue()で以下のテキストをセットする。

=HYPERLINK("http://www.example.org", "事例用ドメイン")

こんな感じ

sheet.getRange(n, m).setValue('=HYPERLINK("'+ url + '","'+ text +'")');

セルの色

背景色

    sheet.getRange('A1:J1').setBackground('#351c75');

文字色

    sheet.getRange('A1:J1').setFontColor('#fefefe');

サイズの調整

自動設定

sheet.autoResizeColumns(2, 3);

でできるみたいなんだけど、日本語入ってるとだめっぽい

クリア

シート全体

sheet.clear();

型変換

int -> string

intのオブジェクトで.toString()する

数字の0埋め

int_value.toString().padStart(2, '0');

正規表現

replace

string.replace(/regexp/, 'string');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment