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?

More than 3 years have passed since last update.

【JavaScript】 yyyy-mm-dd 表記を yyyy年mm月dd日に変更する(文字列 to 文字列)

Last updated at Posted at 2020-05-18

正規表現を使って変更

下記のように書くことで 2020-01-012020年1月1日 に変更することが可能です。
(もちろん、2020-12-252020年12月25日 になります)

date.js
let beforeDate = '2020-01-01';
let afterDate  = beforeDate.replace(/(\d{4})-0?(\d{1,2})-0?(\d{1,2})/, '$1年$2月$3日');

console.log(afterDate);
// 出力:2020年1月1日

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?