dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » .NET » C#
Language: .NET
Expertise: Beginner
Aug 9, 2019

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Countdown Timer Function in C#

See how to use this function in C# to discover how many more days are left in a given countdown.

DateTime startDate = DateTime.Now;
DateTime endDate = DateTime.Now.AddDays(-1);
TimeSpan t = startDate - endDate;
double days = t.TotalDays;
string result = "This is the result";

if (days < 0)
{
result = "phew, the date is in the past";
}
else if (date = 0)
{
result = "We are right on the dot";
}
else
{
result = string.format("{0} days to go!", days};
}
Srinath M S
 
Thanks for your registration, follow us on our social networks to keep up-to-date