将 '2023-08' 格式日期转换为 '2023-08-01' 的方法
您可以使用以下方法将得到的'reportingPeriodDate'从'2023-08'转换为'2023-08-01':
- 将'reportingPeriodDate'转换为Date对象:
const reportingPeriodDateObj = new Date(reportingPeriodDate);
- 使用'toISOString'方法将Date对象转换为ISO 8601格式的字符串:
const reportingPeriodDateString = reportingPeriodDateObj.toISOString();
- 使用'substring'方法截取所需的日期部分:
const formattedReportingPeriodDate = reportingPeriodDateString.substring(0, 10);
最终,'formattedReportingPeriodDate'将包含'2023-08-01'。您可以将其用于您的需求。
完整的代码如下所示:
handleUpdate(row) {
this.reset();
const reportingPeriodDate = this.selection.map((item) => item.reportingPeriodDate);
const reportingPeriodDateObj = new Date(reportingPeriodDate);
const reportingPeriodDateString = reportingPeriodDateObj.toISOString();
const formattedReportingPeriodDate = reportingPeriodDateString.substring(0, 10);
this.params.companyId = this.companyId;
this.params.incomeReportingCode = this.incomeReportingCode;
editReportingDonationDeduction(this.params, formattedReportingPeriodDate).then((response) => {
console.log(response, '修改综合所得申报');
this.form = response.data;
console.log(this.form, '修改综合');
this.open = true;
this.title = '修改综合所得申报-稿酬所得';
});
},
请注意,这仅适用于将'2023-08'转换为'2023-08-01'的情况。如果您有其他日期格式或需求,请根据需要进行修改。
原文地址: http://www.cveoy.top/t/topic/pgoF 著作权归作者所有。请勿转载和采集!