C\#시간(몇 개의 상용 시간,프로그램 실행 시간,페이지 실행 시간)
                                            
 5332 단어  C#
                    
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
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
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());
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
3.페이지 실행 시간 계산 하기: Global.aax.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 + "   ");
        }.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.