aro*_*ron 6 c# datetime billing
我为我的新计费系统编写了一些代码.目的是在每个月的同一天向客户收费.(不是本月的第1天或最后一天)
static bool NeedToBill(DateTime planLastBilled, DateTime cycleDate)
{
// is today the same date as the cycleDate AND is was the planLastBilled not the same day as today?
if (DateTime.UtcNow.Day.Equals(cycleDate.Day) && !DateTime.UtcNow.Day.Equals(planLastBilled))
return true;
else
return false;
}
Run Code Online (Sandbox Code Playgroud)
两个陷阱是:
这里有一个共同的最佳做法吗?
所以看起来有很多事要检查
谢谢!
好吧,我相信我已经完全结束了了。\n这很简单并且涵盖了所有内容:
\n\nbool NeedToBill = ((DateTime.UTCNow \xe2\x80\x93 LastBillDate) >= 30 Days)\nRun Code Online (Sandbox Code Playgroud)\n\n它不一定会在同一天计费,但已经足够接近了。\n如果交易被拒绝一天,或者计划任务在下次运行时 1 天没有运行,它会选择它,这也增加了灵活性向上。
\n