Reputation: 593
I am writing a bot that gives a countdown to a specific day and time everyweek. In this case we will say today is Friday. I want to get the countdown till Saturday at 8. The problem with my current format is that it has a defined date. How can I have it work for every Saturday without a defined date for DateTime.Parse
? If I cannot do it that way, what is a good alternative?
DateTime dt;
TimeSpan t;
string countDown = "";
dt = DateTime.Now;
dt.DayOfWeek.ToString();
if (dt.DayOfWeek.ToString() == "Friday")
{
//Get these values however you like.
DateTime productLaunchDateTime = DateTime.Parse("02/25/2017 08:00:00 PM");
DateTime startDate = DateTime.Now;
//Calculate countdown timer.
t = productLaunchDateTime - startDate;
countDown = string.Format("Release in {0} Days, {1} Hours, {2} Minutes, {3} Seconds", t.Days, t.Hours, t.Minutes, t.Seconds);
}
Upvotes: 0
Views: 131
Reputation: 937
You can check this post. Quartz is what you looking for. Also you can check task scheduler for simple solution.
How to execute code at a given time every day?
Upvotes: 1