Event for each year, DateTime checking version.

I alway forget this.

public int
	m_TriggerMonth = 12,
	m_TriggerDay = 29,
	m_EventDays = 10;

DateTime StartDate = new DateTime(DateTime.UtcNow.Year, m_TriggerMonth, m_TriggerDay);
DateTime EndDate = StartDate.AddDays(m_EventDays);
EndDate.AddDays(EndDate.Year - StartDate.Year);

if ((DateTime.UtcNow >= StartDate && DateTime.UtcNow <= EndDate) ||
	(DateTime.UtcNow >= StartDate.AddYears(-1) && DateTime.UtcNow <= EndDate.AddYears(-1)))
{
	// will happen on each year
}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

*

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料