LoginSignup
0
0

More than 3 years have passed since last update.

【Node.js】日時処理を扱う方法

Posted at

プログラミング勉強日記

2021年2月25日

日付処理を使うための準備

 Node.jsで日付処理を扱うために、今回はdate-utilsを使用する。
 date-utilsはnpmパッケージの1つで、簡単にインストールすることができる。

date-utilsをインストールする
$ npm install date-utils

現在時刻を表示する

// date-utilsを呼び出す
require('date-utils');
let now = new Date();
console.log(now.toFormat('YYYY年MM月DD日 HH24時MI分SS秒'));
console.log(now.toFormat('YY年M月D日 H時MI分SS秒'));
console.log(now.toFormat('DDD MMM DD YYYY HH24:MI:SS'));
console.log(now.toFormat('M/D/YY'));
実行結果
2021年02月25日 01時52分13秒
21年2月25日 1時52分13秒
Thu Feb 25 2021 01:52:13
2/25/21

参考文献

日付に関する実装!Node.jsで書くDateの使い方【初心者向け】

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