从日期日期函数中删除时间 [英] removing time from angular date function

查看:141
本文介绍了从日期日期函数中删除时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的应用上设置了日期格式.

I have currently set up date formatting on my app..

HTML

<span ng-bind="convertToDate(myDate) | date: 'medium'" id="dtText"></span>

角度

$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 ?

推荐答案

仅使用

<span ng-bind="myDate | date: 'mediumDate'" id="dtText"></span>

无需转换.

convertDate函数不起作用的原因是Date.setDate仅设置日期值的日期部分,而时间部分保持不变.要重置时间部分,您必须像这样分别重置它们

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

dateOut.setSeconds(0);
dateOut.setMinutes(0);
dateOut.setHours(0);

这篇关于从日期日期函数中删除时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆