'does the filter with new date() accept format other than yyyy-mm-dd?
I have a response from mydatepicker in the following format
{
"isRange":false,
"singleDate":{
"date":{
"year":2022,
"month":5,
"day":13
},
"jsDate":"2022-05-13T03:00:00.000Z",
"formatted":"13-05-2022",
"epoc":1652410800
},
"dateRange":null
}
I have a filter that uses the new date(), but it seems that it doesn't accept it accepting the date in the value dd-mm-yyyy and I would need to display it like this, not like this yyyy-mm-dd
filterPeriodos() {
const d = new Date(this.formGeral.value.data.singleDate?.formatted + 'T23:59');
if (this.storeS.layout.emp.id === 1) {
if(this.formGeral.value.entregaBool){
return this.periodos.filter( transpId => transpId.ativo === (1) && transpId.transporte_id === (this.metodoId) && transpId.week[d.getDay()] === 1 ) ;
}
}
return this.periodos;
}
would anyone have any suggestions?
Solution 1:[1]
To get the end of a day, first convert the parse-able text into a date, then manipulate that date.
let object = this.formGeral.value.data; // for our sanity
let jsDate = new Date(object.singleDate.jsDate);
jsDate.setUTCHours(23,59,59,999);
Keep the formatted
string around for display, but do any date computations on the real date object.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | danh |