Moment.js 或经典 JS 的日期格式,更改日期和月份的位置?

Date format with Moment.js or classic JS, change places of day and month?

我以这种格式从源中获取日期值: 02.08.2016 / Day.Month.Year,正确。

但是JavaScript理解这个逆,Month.Day.Year。

我用 Moment.js 尝试了一些方法,例如:

moment('15.08.2016').format('MM.DD.YYYY');

我的 JsFiddle 是:http://jsfiddle.net/PAc3j/389/ 有一些结果可见,请看输出,变量dateThree: Invalid date

我的问题是,如何使用 Moment.js 或经典 JavaScript 来实现?

您可以像这样指定输入日期字符串的格式。

moment('15.08.2016', 'DD.MM.YYYY').format('MM.DD.YYYY');

http://momentjs.com/docs/#/parsing/string-format