31
21

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.

JavaScriptでDateをyyyy/MM/dd HH:mm:ssにフォーマットする方法 (date-fnsなどのライブラリなしで)

Posted at

JavaScriptでDateオブジェクトをdate-fnsなどのライブラリなしに年月日形式(yyyy/MM/dd HH:mm:ss)に変換する方法です。

日付のフォーマットにはIntl.DateTimeFormatを用います。

const date = new Date(2001, 0, 2, 3, 4, 5);
const d = new Intl.DateTimeFormat("ja-jp", {
  year: "numeric",
  month: "2-digit",
  day: "2-digit",
  hour: "2-digit",
  minute: "2-digit",
  second: "2-digit",
}).format(date);
console.log(d); //=> "2001/01/02 03:04:05"
31
21
3

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
31
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?