I have currently set up date formatting on my app..
我现在已经在我的应用上设置了日期格式。
Html
Html
<span ng-bind="convertToDate(myDate) | date: 'medium'" id="dtText"></span>
Angular
角
$scope.myDate = new Date();
$scope.convertToDate = function (stringDate) {
var dateOut = new Date(stringDate);
dateOut.setDate(dateOut.getDate());
return dateOut;
};
I have the function working however it is displaying the time which i would like to remove. Just wondering what i would need to add to my function in order to prevent the time from displaying ?
我让函数工作,但它显示的是我想要删除的时间。只是想知道为了防止显示时间,我需要添加什么功能?
2 个解决方案
#1
0
How about just using
如何使用
<span ng-bind="myDate | date: 'mediumDate'" id="dtText"></span>
No need to convert it.
不需要转换。
The reason your convertDate
function doesn't work is that Date.setDate
only sets the date portion of the date value, leaving the time components intact. To reset the time components you would have to reset them individually something like
convertDate函数不能工作的原因是日期。setDate只设置日期值的日期部分,而保留时间组件不变。要重设时间分量,你必须将它们分别重设
dateOut.setSeconds(0);
dateOut.setMinutes(0);
dateOut.setHours(0);
#2
2
Specify format of date as argument
指定日期格式作为参数。
<span ng-bind="myDate | date: 'MMM d,y'" id="dtText"></span>
#1
0
How about just using
如何使用
<span ng-bind="myDate | date: 'mediumDate'" id="dtText"></span>
No need to convert it.
不需要转换。
The reason your convertDate
function doesn't work is that Date.setDate
only sets the date portion of the date value, leaving the time components intact. To reset the time components you would have to reset them individually something like
convertDate函数不能工作的原因是日期。setDate只设置日期值的日期部分,而保留时间组件不变。要重设时间分量,你必须将它们分别重设
dateOut.setSeconds(0);
dateOut.setMinutes(0);
dateOut.setHours(0);
#2
2
Specify format of date as argument
指定日期格式作为参数。
<span ng-bind="myDate | date: 'MMM d,y'" id="dtText"></span>