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] Set default format #73

Open
andre-paulo98 opened this issue Nov 22, 2020 · 6 comments
Open

[QUESTION] Set default format #73

andre-paulo98 opened this issue Nov 22, 2020 · 6 comments

Comments

@andre-paulo98
Copy link

So if in my application, I use 90% of the time, DD/MM/YYYY, is there anyway that the default format is that one? Instead of manually formatting each time?

@thibaudallie
Copy link

add this plugin

@alfaben12
Copy link

just add .format('YYYY')

ex: $moment(datetime).format('YYYY')
thats work for me

@mrleblanc101
Copy link

You could create a utility function. So instead of calling moment, you call your function which has the correct format.

Copy link
Member

farnabaz commented Feb 3, 2021

Changing $moment.defaultFormat will do the trick. Checkout moment/moment#3176 (comment)

@timyourivh
Copy link

add this plugin

just add .format('YYYY')

You could create a utility function. So instead of calling moment, you call your function which has the correct format.

Changing $moment.defaultFormat will do the trick. Checkout moment/moment#3176 (comment)

Wouldn't it be easier if there was a way to pass it through the module options? Because why would I use this module if I could create a plugin to do the same and have more configuration available. It defeats the whole purpose of this module in my opinion. I don't know if this option already exists but here is my plugin example:

plugins/moment.js:

import moment from 'moment'

moment.defaultFormat = '[test] DD-MM-YYYY HH:mm'

export default (_, inject) => {
  inject('moment', moment)
}
<template>
  <div>{{ $moment().format() }}</div>
  <!-- Returned: test 21-10-2021 14:11 -->
<template>

I may create a PR in the future to add an option like this into the config of this module

@timyourivh
Copy link

timyourivh commented May 18, 2022

I did create a PR to add this feature but I think they've abandoned this package or forgot about it. No response since I submitted it on February 8. 😕
I mean it's not that hard right?

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

Successfully merging a pull request may close this issue.

6 participants