Browse Source

添加计时工具

yuzhengyang 8 years ago
parent
commit
0d988d6c4e
2 changed files with 53 additions and 0 deletions
  1. 52 0
      Fork.Net/Y.Utils/TimeUtils/TimerTool.cs
  2. 1 0
      Fork.Net/Y.Utils/Y.Utils.csproj

+ 52 - 0
Fork.Net/Y.Utils/TimeUtils/TimerTool.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Utils.TimeUtils
+{
+    public class TimerTool
+    {
+        private DateTime BeginTime { get; set; }
+        private DateTime EndTime { get; set; }
+        private TimerTool() { }
+        public TimerTool(bool isStart = false)
+        {
+            if (isStart)
+                Begin();
+        }
+        public void Begin()
+        {
+            BeginTime = DateTime.Now;
+        }
+        public void End()
+        {
+            EndTime = DateTime.Now;
+        }
+        public double m
+        {
+            get
+            {
+                End();
+                return (EndTime - BeginTime).TotalMinutes;
+            }
+        }
+        public double s
+        {
+            get
+            {
+                End();
+                return (EndTime - BeginTime).TotalSeconds;
+            }
+        }
+        public double ms
+        {
+            get
+            {
+                End();
+                return (EndTime - BeginTime).TotalMilliseconds;
+            }
+        }
+    }
+}

+ 1 - 0
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -98,6 +98,7 @@
     <Compile Include="TestTest\OperatorTest.cs" />
     <Compile Include="TestTest\OperatorTest.cs" />
     <Compile Include="TimeUtils\DateTimeConvert.cs" />
     <Compile Include="TimeUtils\DateTimeConvert.cs" />
     <Compile Include="TimeUtils\DateTimeTool.cs" />
     <Compile Include="TimeUtils\DateTimeTool.cs" />
+    <Compile Include="TimeUtils\TimerTool.cs" />
     <Compile Include="TxtUtils\IniTool.cs" />
     <Compile Include="TxtUtils\IniTool.cs" />
     <Compile Include="TxtUtils\LogTool.cs" />
     <Compile Include="TxtUtils\LogTool.cs" />
     <Compile Include="TxtUtils\TxtTool.cs" />
     <Compile Include="TxtUtils\TxtTool.cs" />