Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to use updateLocale in nuxtjs/dayjs? #347

Open
GabrielOkane opened this issue Sep 9, 2021 · 2 comments
Open

Question: How to use updateLocale in nuxtjs/dayjs? #347

GabrielOkane opened this issue Sep 9, 2021 · 2 comments

Comments

@GabrielOkane
Copy link

I would like to change the format for relativeTime: https://day.js.org/docs/en/customization/relative-time. But i dont know how implement in nuxtconfig

@k4sud0n
Copy link

k4sud0n commented Oct 24, 2021

Make a dayjs.js file in plugins folder and write code below.

export default function ({ $dayjs }) {
  $dayjs.updateLocale('en', {
    relativeTime: {
      future: 'in %s',
      past: '%s ago',
      s: 'a few seconds',
      m: 'a minute',
      mm: '%d minutes',
      h: 'an hour',
      hh: '%d hours',
      d: 'a day',
      dd: '%d days',
      M: 'a month',
      MM: '%d months',
      y: 'a year',
      yy: '%d years',
    },
  })
}

And add this plugin to nuxt.config.js.

// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [ '~/plugins/dayjs'],

Finally, add updateLocale to dayjs config in nuxt.config.js

...

dayjs: {
    locales: ['en'],
    defaultLocale: 'en',
    defaultTimeZone: 'America/New_York',
    plugins: ['timezone', 'relativeTime', 'updateLocale'],
  },

...

@cdwmhcc
Copy link

cdwmhcc commented Nov 9, 2021

@k4sud0n How to use in nuxt3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants