我正在一个项目中使用 AngularJS Datepicker。发布日期时,我成功取回数据,但问题是我得到的日期格式为 2018-05-23T06:00:00.000Z。
有没有办法让它只显示2018-05-23?
这就是我当前的日期选择器
// Date picker
$scope.myDate = new Date();
$scope.minDate = new Date(
$scope.myDate.getFullYear(),
$scope.myDate.getMonth() - 2,
$scope.myDate.getDate());
$scope.maxDate = new Date(
$scope.myDate.getFullYear(),
$scope.myDate.getMonth() + 2,
$scope.myDate.getDate());
$scope.onlyWeekdaysPredicate = function (date) {
var day = date.getDay();
return day === 1 || day === 2 || day === 3 || day === 4 || day === 5;
};
这是我的 HTML
<md-input-container style="margin:0px;position:relative;right:15px;font-size:15px">
<md-datepicker ng-model="user.next_class" ng-model="myDate" md-placeholder="Pick a date" md-date-filter="onlyWeekdaysPredicate" date:"MM/dd/yyyy 'at' h:mma" md-open-on-focus></md-datepicker>
</md-input-container>
我听说过使用 Moment.JS 来实现此目的,目前正在尝试寻找可能有帮助的资源。
最佳答案
您可以将日期转换为 toISOString()
,然后从中切出日期部分
var date1 = "2018-05-23T06:00:00.000Z";
var d = new Date(date1).toISOString().slice(0, 10);
console.log(d)
关于javascript - AngularJS Material Datepicker 更改格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50399070/