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

Relative time #1341

Closed
samullman opened this issue Jan 19, 2021 · 3 comments
Closed

Relative time #1341

samullman opened this issue Jan 19, 2021 · 3 comments

Comments

@samullman
Copy link

samullman commented Jan 19, 2021

import dayjs from "dayjs";

var relativeTime = require('dayjs/plugin/relativeTime')
dayjs.extend(relativeTime)

const timeFrom = dayjs().from(dayjs('2015-01-01'), true) 
// timeFrom = 6 years

Is there any way to customize the format of relative time? (XX years XX months XX days XX minutes XX seconds)

@iamkun
Copy link
Owner

iamkun commented Jan 19, 2021

@samullman
Copy link
Author

samullman commented Jan 19, 2021

I'm here.

var updateLocale = require('dayjs/plugin/updateLocale')
dayjs.extend(updateLocale)

dayjs.updateLocale('en', {
  relativeTime: {
    yy: "%d years"
  }
})

Almost everything I do results in NaN ... Sry noob here ... I thought I would format this relativeTime object but not getting anywhere with it

@iamkun
Copy link
Owner

iamkun commented Jan 19, 2021

You should pass the whole relativeTime config object, not part of it.

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

2 participants