C# 时间(几个常用时间,程序运行计时,页面运行计时)
2010-12-15 17:49
246 查看
1.DateTime
DateTime now = System.DateTime.Now;
now.ToString(); //显示:
2006/08/30 17:31:02
now.ToString("yyyy-mm-dd
hh:MM:ss"); //显示: 2006-08-30
05:39:11
now.ToString("yyyy-mm-dd HH:mm:ss"); //显示:
2006-08-30 17:40:50
System.DateTime.MaxValue.ToString(); //显示: 9999/12/31
23:59:59
System.DateTime.MinValue.ToString();
//显示: 0001/01/01 0:00:00
now.ToLongDateString(); //显示: 2006年8月30日
now.ToLongTimeString();
//显示: 17:34:23
now.ToShortTimeString();
//显示: 17:34
now.ToString() + " " + now.Millisecond.ToString();
//显示: 2006/08/30 17:35:19 484
2.程序运行时间:(单位 : 毫秒)
System.Diagnostics ; //名称空间
int x = 0;
int nu =
0;
Stopwatch sw = new Stopwatch();
sw.Start();
//程序开始
for (int i = 0; i <
1000000; i++)
{
x += i;
}
//程序结束
sw.Stop();
this.label1.Text += ",sum=" + x.ToString();
MessageBox.Show(sw.ElapsedMilliseconds.ToString());
3.计算一个页面执行时间:
在Global.asax.cs文件中增加以下代码:
protected void
Application_BeginRequest(Object sender, EventArgs e)
{
Application["StartTime"] = System.DateTime.Now;
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
System.DateTime startTime =
(System.DateTime)Application["StartTime"];
System.DateTime
endTime = System.DateTime.Now;
System.TimeSpan ts = endTime -
startTime;
Response.Write("页面执行所用时间:" + ts.Milliseconds + "
毫秒");
}
DateTime now = System.DateTime.Now;
now.ToString(); //显示:
2006/08/30 17:31:02
now.ToString("yyyy-mm-dd
hh:MM:ss"); //显示: 2006-08-30
05:39:11
now.ToString("yyyy-mm-dd HH:mm:ss"); //显示:
2006-08-30 17:40:50
System.DateTime.MaxValue.ToString(); //显示: 9999/12/31
23:59:59
System.DateTime.MinValue.ToString();
//显示: 0001/01/01 0:00:00
now.ToLongDateString(); //显示: 2006年8月30日
now.ToLongTimeString();
//显示: 17:34:23
now.ToShortTimeString();
//显示: 17:34
now.ToString() + " " + now.Millisecond.ToString();
//显示: 2006/08/30 17:35:19 484
2.程序运行时间:(单位 : 毫秒)
System.Diagnostics ; //名称空间
int x = 0;
int nu =
0;
Stopwatch sw = new Stopwatch();
sw.Start();
//程序开始
for (int i = 0; i <
1000000; i++)
{
x += i;
}
//程序结束
sw.Stop();
this.label1.Text += ",sum=" + x.ToString();
MessageBox.Show(sw.ElapsedMilliseconds.ToString());
3.计算一个页面执行时间:
在Global.asax.cs文件中增加以下代码:
protected void
Application_BeginRequest(Object sender, EventArgs e)
{
Application["StartTime"] = System.DateTime.Now;
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
System.DateTime startTime =
(System.DateTime)Application["StartTime"];
System.DateTime
endTime = System.DateTime.Now;
System.TimeSpan ts = endTime -
startTime;
Response.Write("页面执行所用时间:" + ts.Milliseconds + "
毫秒");
}
相关文章推荐
- C# 时间函数(几个常用时间,程序运行计时,页面运行计时)
- C# 时间(几个常用时间,程序运行计时,页面运行计时)
- C# 时间(几个常用时间,程序运行计时,页面运行计时).txt
- C# 时间函数(几个常用时间,程序运行计时,页面运行计时)
- C# 时间(几个常用时间,程序运行计时,页面运行计时)
- C# 时间函数(几个常用时间,程序运行计时,页面运行计时)
- C# 时间(几个常用时间,程序运行计时,页面运行计时)
- C#时间函数(程序运行计时,页面运行计时)
- c#常用程序运行时间计算方法
- 计算程序运行时间C#
- c++中常用的计算程序运行时间的方法
- 测量程序运行时间的几个函数
- C#获取程序运行时间
- C/C++如何以秒计时程序运行时间
- C#计算一段程序运行时间的三种方法
- C#计算程序的运行时间
- C#2.0中获取程序的运行时间
- c# 仿照计划任务(定时提示、定时运行程序、定时打开url(前台/后台))/每天/每周/每月/一次 多时间段
- C# 测试程序运行时间
- C#2.0中获取程序的运行时间