我在我的项目和格式化日期中使用Moment.js如下:
var locale = window.navigator.userLanguage || window.navigator.language;
moment.locale(locale);
someDate.format("L");
Run Code Online (Sandbox Code Playgroud)
它运作良好但有时我需要显示没有年份的日期.我不能使用类似的东西,someDate.format("MM/DD")因为在某些语言中它应该是someDate.format("DD/MM").我需要一些想法,L,LL,LLL但没有一年.
我能做什么?
LTS : 'h:mm:ss A',
LT : 'h:mm A',
L : 'MM/DD/YYYY',
LL : 'MMMM D, YYYY',
LLL : 'MMMM D, YYYY LT',
LLLL : 'dddd, MMMM D, YYYY LT'
Run Code Online (Sandbox Code Playgroud) 有没有更好的方法可以从包含位置适当分隔符的日期中只获取日期和月份?
我有一个先获取分隔符的解决方案:
function getDateSep() {
var temp = moment().format('L');
var locale = moment().locale;
var datesep = temp.substring(5, 6);
return datesep;
}
Run Code Online (Sandbox Code Playgroud)
然后像这样构建日期:
var sep = function getDateSep()
var date = date.format('D' + sep + 'M'+ sep)
Run Code Online (Sandbox Code Playgroud)
是否有动态构建整个日期的解决方案?
我想要达到的结果是: 31.01 (dd.mm) 31/01 (dd/mm) 01.31 (mm.dd) 01/31 (mm/dd) 等