How to check if the Year is Leap Year or Not? Using DateTime keyword we can easily find out whether the Year is Leap Year or Not in C#.
int varYear = 2010;
bool varResult = DateTime.IsLeapYear(varYear);
if (varResult.Equals(true))
{
Response.Write(varYear + " is a Leap Year");
}
else
{
Response.Write(varYear + " is not a Leap Year");
}
The .NET Framework allows developers to use the same set of skills to rapidly buid great applications for the web, windows, services and more.
Calculate the Time taken by a web page to execute
How to Calculate time taken by a web page to excute? Or Calculate execution time of a web page?
Here is a simple solution help you find out the number of Milliseconds or seconds or minutes taken by a web page to execute.
1. Copy below code in your Global.asax file.
2. Once you run your .aspx page, below code will display Number of time taken by a web page to execute.
void Application_BeginRequest(object sender, EventArgs e)
{
Context.Items.Add("startime", DateTime.Now);
}
void Application_EndRequest(object sender, EventArgs e)
{
//Get the start time
DateTime dt =(DateTime)Context.Items["startime"];
//calculate the time difference between start and end of request
TimeSpan ts = DateTime.Now - dt; // Display time in Milliseconds
Response.Write("Number of Milliseconds for execution of this page "+" - "+ ts.TotalMilliseconds);
// Display time in Seconds
Response.Write("Number of Seconds for execution of this page " + " - " + ts.TotalSeconds);
// Display time in minutes
Response.Write("Number of Minutes for execution of this page " + " - " + ts.TotalMinutes);
}
Here is a simple solution help you find out the number of Milliseconds or seconds or minutes taken by a web page to execute.
1. Copy below code in your Global.asax file.
2. Once you run your .aspx page, below code will display Number of time taken by a web page to execute.
void Application_BeginRequest(object sender, EventArgs e)
{
Context.Items.Add("startime", DateTime.Now);
}
void Application_EndRequest(object sender, EventArgs e)
{
//Get the start time
DateTime dt =(DateTime)Context.Items["startime"];
//calculate the time difference between start and end of request
TimeSpan ts = DateTime.Now - dt; // Display time in Milliseconds
Response.Write("Number of Milliseconds for execution of this page "+" - "+ ts.TotalMilliseconds);
// Display time in Seconds
Response.Write("Number of Seconds for execution of this page " + " - " + ts.TotalSeconds);
// Display time in minutes
Response.Write("Number of Minutes for execution of this page " + " - " + ts.TotalMinutes);
}
Subscribe to:
Posts (Atom)