0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

formatDate メモ

Posted at

function formatDate(dateString) {
if (!dateString) return "未設定"; // null, undefined, 空文字の対策

let date = new Date(dateString);

// `Invalid Date` のチェック(無効な日付なら "未設定")
if (isNaN(date.getTime())) {
    return "未設定";
}

// 年・月・日を取得して `YYYY/MM/DD` の形式に変換
let year = date.getFullYear();
let month = String(date.getMonth() + 1).padStart(2, "0"); // 0始まりなので +1
let day = String(date.getDate()).padStart(2, "0");

return `${year}/${month}/${day}`;

}

0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?