简体   繁体   English

角获取当前日期以过滤http.get请求

[英]Angular get current date to filter http.get request

  getStuff(currentUserId: any){
    const today = ?
    const currentUser = JSON.parse(localStorage.getItem('currentUser'));
    const token = currentUser.token;
    const headers = new Headers({'Content-Type': 'application/json','Authorization': 'Bearer ' + token})
    return this.http.get(this.url + '/odata/User('+currentUserId+')/Stuff$filter=Date ????',{headers: headers})}

In this function I get some Stuff from my Api and everything I get has a Date. 在此功能中,我从Api中获得了一些东西,并且得到的所有东西都有一个日期。 I want to filter the http.get request for stuff thats date is today or in the future. 我想过滤http.get请求,以获取日期为今天或将来的内容。

My Problem is how do I get todays Date and how do I filter the stuff I want? 我的问题是如何获取今天的日期以及如何过滤所需的内容?

The Date Format in my Database is like that for example "2017-12-21 00:00:00.000" 我数据库中的日期格式类似于“ 2017-12-21 00:00:00.000”

You can format the date as you like, 您可以根据需要设置日期格式,

Either doing : 要么做:

"$filter=" + date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() ...etc

See here for more info : https://www.w3schools.com/js/js_date_methods.asp 请参阅此处以获取更多信息: https : //www.w3schools.com/js/js_date_methods.asp

Or using the javascript format functions : 或使用javascript格式函数:

date.toLocaleDateString();

And then converting it back to a date on the server side 然后将其转换回服务器端的日期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM