到期日提醒,到期日前30天

时间:2018-10-16 06:49:11

标签: c# wpf

使用WPF应用程序,我是否有办法安排警报消息在到期日前30天显示? 我所拥有的是用户订阅的ValidFromDate,ValidToDate。

3 个答案:

答案 0 :(得分:1)

DateTime date= ValidToDate.AddDays(-30);

答案 1 :(得分:0)

例如:

var ValidToDate = new DateTime(2018, 11, 14); // this date is just an example
var expiriesInDays = (int)(ValidToDate - DateTime.Now).TotalDays; // calculate remaining days
if(expiriesInDays <= 30) // you can change the expression to equals if you just want show this message for the specific day when there are 30 days left
{
    MessageBox.Show($"Your subscription will end in {expiriesInDays} days");
}

答案 2 :(得分:0)

如前所述,您拥有的是ValidToDate,

那么您可以在30天之前检查到期时间,

if(currentDate == ValidToDate.AddDays(-30))
{
  // do your logic
}