How to use the dateformat.i18n function in dateformat

To help you get started, we’ve selected a few dateformat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 3846masa / lit-date / benchmarks / src / advanced.bench.js View on Github external
import moment from 'moment';
import 'moment/locale/ja';
import { DateTime } from 'luxon';
import fecha from 'fecha';
import { format as dateFnsFormat } from 'date-fns';
import dateFnsLocaleJa from 'date-fns/locale/ja';
import dateformat from 'dateformat';
import litdate from 'lit-date';

const date = new Date('2000-01-06T12:34:56.789Z');
const expected = '1月6日(木)';

// Prepare
const dayOfWeekToName = ({ dayOfWeek }) => ['日', '月', '火', '水', '木', '金', '土'][dayOfWeek];
Object.assign(dateformat.i18n, {
  dayNames: ['日', '月', '火', '水', '木', '金', '土'],
});
Object.assign(fecha.i18n, {
  dayNamesShort: ['日', '月', '火', '水', '木', '金', '土'],
});

suite('Advanced usage', () => {
  benchmark('moment', () => {
    const actual = moment(date)
      .locale('ja')
      .format('M月D日(ddd)');
    console.assert(actual === expected);
  });
  benchmark('luxon', () => {
    const actual = DateTime.fromJSDate(date)
      .setLocale('ja')

dateformat

A node.js package for Steven Levithan's excellent dateFormat() function.

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis

Popular dateformat functions