将订阅开始日期添加 20 天

从付费服务回调后(当用户支付新订阅时)我想将他的新订阅保存到他/她在数据库中的帐户中。使用 Mongoose 我想在用户帐户中保存新的订阅开始和结束日期,如下所示:

const start = Date.now();

const end = ?

const subscription = { 
    start: start,end: end,}

account.subscriptions.push(subscription);

await account.save();

我可以使用 const start = Date.now(); 获取订阅开始日期但是如果这是一个 20 天的套餐,我如何计算订阅的结束日期?

我应该在开始日期前加上 20 天,我该怎么做?

gff138 回答:将订阅开始日期添加 20 天

这是实现您想要的目标的众多方法之一。

let startDate = new Date();
let endDate = new Date();

endDate.setDate(startDate.getDate() + 20);

const subscription = { 
  start: startDate,end: endDate,}

account.subscriptions.push(subscription);

await account.save();

,

您可以向日期对象添加任何时间,因此如果您计算 20 天内的毫秒数,您可以将其添加到日期中,然后您的日期是未来 20 天

<ng-template arrow-div #otherColumns>
  Here is a Number
</ng-template>

本文链接:https://www.f2er.com/4912.html

大家都在问