moment-module icon indicating copy to clipboard operation
moment-module copied to clipboard

[QUESTION] Set default format

Open andre-paulo98 opened this issue 4 years ago • 6 comments

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?

andre-paulo98 avatar Nov 22 '20 23:11 andre-paulo98

add this plugin

thibaudallie avatar Dec 22 '20 09:12 thibaudallie

just add .format('YYYY')

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

alfaben12 avatar Dec 25 '20 11:12 alfaben12

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

mrleblanc101 avatar Jan 05 '21 20:01 mrleblanc101

Changing $moment.defaultFormat will do the trick. Checkout https://github.com/moment/moment/issues/3176#issuecomment-638011241

farnabaz avatar Feb 03 '21 11:02 farnabaz

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

sneakylenny avatar Oct 21 '21 14:10 sneakylenny

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?

sneakylenny avatar May 18 '22 08:05 sneakylenny