2
1

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.

業務で必要となることが割とあるけど、コードを組むまでもない計算や変換のjsのメモとなります。
ブラウザのデベロッパーツールを起動してjsを実行するだけで結果がわかるので重宝してます。

現在時刻のUNIXタイム(ミリ秒)出力

Date.now(); // 1646227190720
new Date().getTime(); // 1646227352970

UNIXタイム(ミリ秒)から現在時刻へ

new Date(1646227190720).toLocaleString('ja-JP'); // '2022/3/2 22:19:50'

文字列をURLエンコード

encodeURI('カステラ'); // '%E3%82%AB%E3%82%B9%E3%83%86%E3%83%A9'

URLエンコード文字列のデコード

decodeURI('%E3%82%AB%E3%82%B9%E3%83%86%E3%83%A9'); // 'カステラ'

JSON整形

var input = {"name":"カステラ","size":123,"item":[{"name":"","type":"small","price":100},{"name":"","type":"medium","price":500},{"name":"","type":"large","price":1000}]};
console.log(JSON.stringify(input, null, 4)); // 第三引数はインデント長
console.log(JSON.stringify(input, null, '\t')); // tabインデント

Base64エンコード

btoa(encodeURIComponent('taro:password01')); // 'dGFybyUzQXBhc3N3b3JkMDE='

Base64エンコード文字列のデコード

decodeURIComponent(atob('dGFybyUzQXBhc3N3b3JkMDE=')); // 'taro:password01'

数値3桁カンマ区切り

(12345556789).toLocaleString(); // '12,345,556,789'

先頭0埋め

'123'.padStart(10, '0'); // 0000000123
('0000000000' + 123).slice(-10); // 0000000123
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?