7
2

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.

moment.jsからdayjsに移行:曜日の表示

Posted at

日本語の曜日表示の作業メモです

移行前

  • updateLocaleでlocaleをjaに更新
  • updateLocaleでlocaleの曜日表示を設定(ここがjaのデフォルト設定と同じなので、実は要らなかった)
import moment from 'moment';

// momentの言語設定
moment.updateLocale('ja', {
  weekdays: ['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日'],
  weekdaysShort: ['', '', '', '', '', '', ''],
});

移行後

  • dayjs/locale/jaのインポートが必須
  • dayjsのプラグインを特にnpm install必要がない
  • ロケールjaで十分なのでupdateLocaleしない
import dayjs from 'dayjs';
import 'dayjs/locale/ja';

dayjs.locale('ja');

動作確認

console.log(dayjs().format('YYYY/MM/DD(ddd) HH:mm')); // 2021/06/04(金) 08:58
7
2
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
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?