简体   繁体   中英

Issue with date-picker in angular

There is some kind of "campaign duration" which means you are able to choose date between first and last day in month. If you choose date which is not between first and last day in month, for example some date from next month, the Backend API will return an "Input param error".

if I choose the last date inside date selector(30th day in month), the Backend API will return an "Input param error". That means he count 30th day like 1st day in next month. I should Change date selection with one day less, to be when I choose 30th day I should before send date by api, discount that number for one. By the way date is in string format. I need help how to discount string number for one before sending that date on api? 在此处输入图片说明

您可以使用momentjs将字符串转换为日期并减去天,如下所示:

selectedEndDate = moment(selectedEndDate, 'DD/M/YYYY').subtract(1, 'day');

You can subtract one day from your date.

First you need to create a date from your string:

var dateFromString = '2011-04-11T10:20:30Z';
let newDate = new Date(dateFromString);

and then subtract one day from that date:

newDate.setDate(newDate.getDate() - 1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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