gpt4 book ai didi

angularjs - 使用 Angular 日期过滤器如何从 MM/DD/YYYY 格式的日期获取星期几?

转载 作者:行者123 更新时间:2023-12-03 06:51:52 24 4
gpt4 key购买 nike

需要从给定日期(4/25/2017)获取日期,即周一、周二等,其格式为MM/DD/YYYY,而不使用自定义过滤器。

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="datCtrl">
<p>Date = {{ today | date:'EEE' }}</p>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('datCtrl', function($scope) {
$scope.today = '4/25/2017'
});
</script>

<p>Need to get Day i.e Mon,Tues etc from above date which is in MM/DD/YYYY format without using custom filter. </p>

</body>
</html>

最佳答案

您需要将日期字符串创建为日期对象:

var app = angular.module('myApp', []);
app.controller('datCtrl', function($scope) {
$scope.today = new Date('4/25/2017')
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="datCtrl">
<p>Date = {{ today | date:'EEE'}}</p>
</div>

<p>Need to get Day i.e Mon,Tues etc from above date which is in MM/DD/YYYY format without using custom filter. </p>

</body>
</html>

关于angularjs - 使用 Angular 日期过滤器如何从 MM/DD/YYYY 格式的日期获取星期几?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43677744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com