プラグイン------momentJs-JavaScriptで日付と時刻を解析、検証、操作、表示します.
momentJsサイト:https://momentjs.com/
または体積の小さいdayjsを使用します.https://github.com/iamkun/dayjs
インストール:
フォーマット日:
相対時間:
カレンダ時間:
多言語環境のサポート:
dayjs構文:
国際化
Day.jsは国際化を非常にサポートしています.
ただし、それらを使用しない限り、それらは構築に含まれません.
プラグイン(Plugin):
プラグインは独立したモジュールで、Dayに追加できます.jsは、機能を拡張したり、新しい機能を追加したりします.
または体積の小さいdayjsを使用します.https://github.com/iamkun/dayjs
インストール:
npm install moment --save # npm
yarn add moment # Yarn
Install-Package Moment.js # NuGet
spm install moment --save # spm
meteor add momentjs:moment # meteor
bower install moment --save # bower (deprecated)
npm install dayjs --save
フォーマット日:
moment().format('MMMM Do YYYY, h:mm:ss a'); // 14 2019, 2:04:23
moment().format('dddd'); //
moment().format("MMM Do YY"); // 8 14 19
moment().format('YYYY [escaped] YYYY'); // 2019 escaped 2019
moment().format(); // 2019-08-14T14:04:23+08:00
相対時間:
moment("20111031", "YYYYMMDD").fromNow(); // 8
moment("20120620", "YYYYMMDD").fromNow(); // 7
moment().startOf('day').fromNow(); // 14
moment().endOf('day').fromNow(); // 10
moment().startOf('hour').fromNow(); // 5
カレンダ時間:
moment().subtract(10, 'days').calendar(); // 2019/08/04
moment().subtract(6, 'days').calendar(); // 14:06
moment().subtract(3, 'days').calendar(); // 14:06
moment().subtract(1, 'days').calendar(); // 14:06
moment().calendar(); // 14:06
moment().add(1, 'days').calendar(); // 14:06
moment().add(3, 'days').calendar(); // 14:06
moment().add(10, 'days').calendar(); // 2019/08/24
// undefined
多言語環境のサポート:
moment.locale(); // zh-hk
moment().format('LT'); // 14:07
moment().format('LTS'); // 14:07:29
moment().format('L'); // 2019/08/14
moment().format('l'); // 2019/8/14
moment().format('LL'); // 2019 8 14
moment().format('ll'); // 2019 8 14
moment().format('LLL'); // 2019 8 14 14:07
moment().format('lll'); // 2019 8 14 14:07
moment().format('LLLL'); // 2019 8 14 14:07
moment().format('llll'); // 2019 8 14 14:07
dayjs構文:
Day.js API , , 。
dayjs('2018-08-08') // parse
dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A') // display
dayjs().set('month', 3).month() // get & set
dayjs().add(1, 'year') // manipulate
dayjs().isBefore(dayjs()) // query
国際化
Day.jsは国際化を非常にサポートしています.
ただし、それらを使用しない限り、それらは構築に含まれません.
import 'dayjs/locale/es' // load on demand
dayjs.locale('es') // use Spanish locale globally
dayjs('2018-05-05').locale('zh-cn').format()
// use Chinese Simplified locale in a specific instance
プラグイン(Plugin):
プラグインは独立したモジュールで、Dayに追加できます.jsは、機能を拡張したり、新しい機能を追加したりします.
import advancedFormat from 'dayjs/plugin/advancedFormat' // load on demand
dayjs.extend(advancedFormat) // use plugin
dayjs().format('Q Do k kk X x') // more available formats