我在这里使用日期和方法 .format() 有一些奇怪的事情Moment.js的对于 Angular.js 项目,问题很简单,当我使用 .toISOString() 打印它时,我得到了正确的日期。但 .format()
完全错误,以下示例显示了这种情况:
代码如下:
var app = angular.module('myApp', []);
app.controller('MyCtrl', function($scope) {
$scope.isoString = moment().week(53).weekday(6).toISOString();
$scope.formatString = moment().week(53).weekday(6).format('Do of MMMM GGGG');
$scope.year = moment().week(53).weekday(6).years();
});
返回结果如下:
Correct ISO String : 2016-01-02T09:40:31.236Z
Incorrect formate String: 2nd of January 2015
Year : 2016
这是plnkr.co中的展示
对此有任何解决方案或描述吗?
最佳答案
使用 YYYY
代替 GGGG
表示年份:
$scope.formatString = moment().week(53).weekday(6).format('Do of MMMM YYYY');
关于javascript - 当前年份最后一周的明年日期的 moment.format(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33934873/