admin管理员组文章数量:1415420
I am setting the locale in momentjs using :
moment.locale('en-GB');
but every time I create a new object I have to use a format string, e.g.:
moment('12/01/2001','DD/MM/YYYY');
Is it possible for me to default moment so that it uses dd-mm-yyy everywhere so I only have to use:
moment('12/01/2001');
I am setting the locale in momentjs using :
moment.locale('en-GB');
but every time I create a new object I have to use a format string, e.g.:
moment('12/01/2001','DD/MM/YYYY');
Is it possible for me to default moment so that it uses dd-mm-yyy everywhere so I only have to use:
moment('12/01/2001');
Share
Improve this question
asked Nov 5, 2014 at 20:03
SturmUndDrangSturmUndDrang
1,9767 gold badges29 silver badges47 bronze badges
2
- github./moment/moment/issues/308 – Andreas Commented Nov 5, 2014 at 20:08
- Per the thread linked by @Andreas' ment, it seems like "no". – maerics Commented Nov 5, 2014 at 20:16
3 Answers
Reset to default 4As pointed out in the ments this seems not to work. You can provide a wrapper function though:
function localeMoment(date){
return moment(date, 'DD/MM/YYYY');
}
This is probably the closest that you can get.
You can wrap the @k-nut function in a more elegant way
String.prototype.toMomentDate = function () {
return moment(this, 'DD/MM/YYYY');
}
and call it on your strings which store dates
var date = '12/01/2001';
date.toMomentDate();
You can use
moment('12/01/2001','L');
"L" will automatically set the current format depend on locale
本文标签: javascriptDefault momentjs to ddmmyyyy formatStack Overflow
版权声明:本文标题:javascript - Default momentjs to dd-mm-yyyy format - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745234222a2648958.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论