Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何停止在angular 2中的筛选器中获取冗余日期_Angular_Date_Datetime_Angular2 Routing_Datetime Format - Fatal编程技术网

如何停止在angular 2中的筛选器中获取冗余日期

如何停止在angular 2中的筛选器中获取冗余日期,angular,date,datetime,angular2-routing,datetime-format,Angular,Date,Datetime,Angular2 Routing,Datetime Format,我在我的过滤器中得到这样的日期 2014年9月26日星期五格林威治标准时间17:00:00 2014年9月26日星期五18:30:00 GMT 2014年9月26日星期五格林威治标准时间22:30:00 而从数据库的过滤器,我得到三个相同的日期像这样 2014年9月26日 2014年9月26日 2014年9月26日 但是我只想要一个 2014年9月26日 那么,我如何才能做到这一点呢?在组件中尝试这个方法,并在其中循环(这将为您提供一个大致的方法) 从'@angular/core'导入{Comp

我在我的过滤器中得到这样的日期

2014年9月26日星期五格林威治标准时间17:00:00
2014年9月26日星期五18:30:00 GMT
2014年9月26日星期五格林威治标准时间22:30:00

而从数据库的过滤器,我得到三个相同的日期像这样

2014年9月26日
2014年9月26日
2014年9月26日

但是我只想要一个
2014年9月26日


那么,我如何才能做到这一点呢?

在组件中尝试这个方法,并在其中循环(这将为您提供一个大致的方法)

从'@angular/core'导入{Component}

@Component({
  selector: 'my-app',
  template:`<h1>My First Angular 2 App</h1>
  <p>{{test | date: 'dd-MMM-yyyy'}} - format: dd/MM/yyyy</p>`
})
export class AppComponent { 
  test : Date = new Date();
}

以下是在组件中尝试此功能并循环使用(这将为您提供一个大致的操作方法)

从'@angular/core'导入{Component}

@Component({
  selector: 'my-app',
  template:`<h1>My First Angular 2 App</h1>
  <p>{{test | date: 'dd-MMM-yyyy'}} - format: dd/MM/yyyy</p>`
})
export class AppComponent { 
  test : Date = new Date();
}

这是好的,这是一个完美的答案

  this.DeliveryDate = json.DateStart != null ? new Date(json.DateStart).setHours(0,0,0) : null;

在设定时间(0,0,0)之前,根据我的问题,只能得到一个日期。

好的,这是完美的答案

  this.DeliveryDate = json.DateStart != null ? new Date(json.DateStart).setHours(0,0,0) : null;

在设定时间(0,0,0)之前,根据我的问题,只能得到一个日期。

利用时间并过滤这些日期这将对您有所帮助。利用时间并过滤这些日期这将对您有所帮助。我可以直接在组件中设置它吗??就像使用setDate()@Aarsh现在检查我的答案你的答案是正确的,但我得到了我的答案,我会更新它。我可以直接在组件中设置它吗??就像使用setDate()@Aarsh现在检查我的答案你的答案是正确的,但我得到了我的答案,我会更新它。