当前位置: 首页>>代码示例>>C#>>正文


C# DateTime.AddSeconds方法代码示例

本文整理汇总了C#中System.DateTime.AddSeconds方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.AddSeconds方法的具体用法?C# DateTime.AddSeconds怎么用?C# DateTime.AddSeconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.AddSeconds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ViewModel

        public ViewModel()
        {
            mgt = new ManagementClass("Win32_Processor");
            procs = mgt.GetInstances();

            CPU = new ObservableCollection<Model>();
            timer = new DispatcherTimer();
            random = new Random();
            time = DateTime.Now;
            cpuCounter = new PerformanceCounter();
            cpuCounter.CategoryName = "Processor";
            cpuCounter.CounterName = "% Processor Time";
            cpuCounter.InstanceName = "_Total";
            ramCounter = new PerformanceCounter("Memory", "Available MBytes");
            ProcessorID = GetProcessorID();
            processes = Process.GetProcesses();
            Processes = processes.Length;
            MaximumSpeed = GetMaxClockSpeed();
            LogicalProcessors = GetNumberOfLogicalProcessors();
            Cores = GetNumberOfCores();
            L2Cache = GetL2CacheSize();
            L3Cache = GetL3CacheSize();
            foreach (ManagementObject item in procs)
                L1Cache = ((UInt32)item.Properties["L2CacheSize"].Value / 2).ToString() + " KB";

            timer.Interval = TimeSpan.FromMilliseconds(1000);
            timer.Tick += timer_Tick;
            timer.Start();
            for (int i = 0; i < 60; i++)
            {
                CPU.Add(new Model(time, 0,0));
                time = time.AddSeconds(1);
            }
        }
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:34,代码来源:ViewModel.cs

示例2: Next

        public override DateTime Next(DateTime time, out bool changed)
        {
            changed = false;

            if (Values.Count < 1)
            {
                return time;
            }
            if (Type == CGtd.DATES_TYPE_EACH)
            {
                return time.AddSeconds(Values[0]);
            }
            if (Type == CGtd.DATES_TYPE_WHEN)
            {
                int idx = time.Second;
                int tmp = NextValue(idx, changed);
                if (tmp > 0)
                {
                    return time.AddSeconds(tmp);
                }
                if (tmp < 0)
                {
                    changed = true;
                    return time.AddMinutes(1).AddSeconds(Values[0] - idx);
                }
            }
            return time;
        }
开发者ID:burstas,项目名称:rmps,代码行数:28,代码来源:Second.cs

示例3: CreateLapsFromElapsedTimes

        public static LapCollection CreateLapsFromElapsedTimes(DateTime startTime, List<double> elapsedTimes, List<RouteSegment> routeSegments)
        {
            LapCollection laps = new LapCollection();
              if (routeSegments.Count == 0) return laps;

              // justify lap times with regard to paused times during the race
              int currentRouteSegmentIndex = 0;
              for (int i = 0; i < elapsedTimes.Count; i++)
              {
            while (startTime.AddSeconds(elapsedTimes[i]) > routeSegments[currentRouteSegmentIndex].LastWaypoint.Time && currentRouteSegmentIndex < routeSegments.Count - 1)
            {
              double stoppedTime = (routeSegments[currentRouteSegmentIndex + 1].FirstWaypoint.Time.Ticks - routeSegments[currentRouteSegmentIndex].LastWaypoint.Time.Ticks) / (double)TimeSpan.TicksPerSecond;
              for (int j = i; j < elapsedTimes.Count; j++)
              {
            elapsedTimes[j] += stoppedTime;
              }
              currentRouteSegmentIndex++;
            }
              }

              // add each lap
              foreach (double et in elapsedTimes)
              {
            if (et > 0) laps.Add(new Lap(startTime.AddSeconds(et), LapType.Lap));
              }

              // add start and end of each route segment as a lap
              foreach (RouteSegment rs in routeSegments)
              {
            laps.Add(new Lap(rs.FirstWaypoint.Time, LapType.Start));
            laps.Add(new Lap(rs.LastWaypoint.Time, LapType.Stop));
              }

              return laps;
        }
开发者ID:romanbdev,项目名称:quickroute-gps,代码行数:35,代码来源:RouteImporterUtil.cs

示例4: CalcTimeMoment

 // ----------------------------------------------------------------------
 public static DateTime CalcTimeMoment( DateTime baseMoment, TimeUnit offsetUnit, long offsetCount = 1, ITimeCalendar calendar = null )
 {
     switch ( offsetUnit )
     {
         case TimeUnit.Tick:
             return baseMoment.AddTicks( offsetCount );
         case TimeUnit.Millisecond:
             DateTime offsetMillisecond = baseMoment.AddSeconds( offsetCount );
             return TimeTrim.Millisecond( offsetMillisecond, offsetMillisecond.Millisecond );
         case TimeUnit.Second:
             DateTime offsetSecond = baseMoment.AddSeconds( offsetCount );
             return TimeTrim.Second( offsetSecond, offsetSecond.Second );
         case TimeUnit.Minute:
             return new Minute(baseMoment, calendar).AddMinutes( ToInt( offsetCount ) ).Start;
         case TimeUnit.Hour:
             return new Hour( baseMoment, calendar ).AddHours( ToInt( offsetCount ) ).Start;
         case TimeUnit.Day:
             return new Day( baseMoment, calendar ).AddDays( ToInt( offsetCount ) ).Start;
         case TimeUnit.Week:
             return new Week( baseMoment, calendar ).AddWeeks( ToInt( offsetCount ) ).Start;
         case TimeUnit.Month:
             return new Month( baseMoment, calendar ).AddMonths( ToInt( offsetCount ) ).Start;
         case TimeUnit.Quarter:
             return new Quarter( baseMoment, calendar ).AddQuarters( ToInt( offsetCount ) ).Start;
         case TimeUnit.Halfyear:
             return new Halfyear( baseMoment, calendar ).AddHalfyears( ToInt( offsetCount ) ).Start;
         case TimeUnit.Year:
             return new Year( baseMoment, calendar ).AddYears( ToInt( offsetCount ) ).Start;
         default:
             throw new InvalidOperationException();
     }
 }
开发者ID:jwg4,项目名称:date-difference,代码行数:33,代码来源:TimeUnitCalc.cs

示例5: Recalculates

        public void Recalculates()
        {
            var dateTime1 = new DateTime(2014, 1, 1, 1, 0, 0);
            var dateTime2 = new DateTime(2014, 1, 1, 1, 1, 0);
            var dateTime3 = new DateTime(2014, 1, 1, 2, 2, 2);
            var serverNameA = new ServerName("A");
            var serverNameB = new ServerName("B");
            var serverNameC = new ServerName("C");

            System.Insert(
                new ServerStamp() { ServerName = serverNameA, Timestamp = dateTime1 },
                new ServerStamp() { ServerName = serverNameA, Timestamp = dateTime1.AddSeconds(1) },
                new ServerStamp() { ServerName = serverNameB, Timestamp = dateTime2 },
                new ServerStamp() { ServerName = serverNameB, Timestamp = dateTime2.AddSeconds(1) },
                new ServerStamp() { ServerName = serverNameC, Timestamp = dateTime3 },
                new ServerStamp() { ServerName = serverNameC, Timestamp = dateTime3.AddSeconds(1) }
                );

            Expect(System.TryGetServerAtStamp(dateTime1.AddSeconds(-1)), Null);
            Expect(System.TryGetServerAtStamp(dateTime1), EqualTo(serverNameA));
            Expect(System.TryGetServerAtStamp(dateTime1.AddSeconds(1)), EqualTo(serverNameA));

            Expect(System.TryGetServerAtStamp(dateTime2.AddSeconds(-1)), EqualTo(serverNameA));
            Expect(System.TryGetServerAtStamp(dateTime2), EqualTo(serverNameB));
            Expect(System.TryGetServerAtStamp(dateTime2.AddSeconds(1)), EqualTo(serverNameB));

            Expect(System.TryGetServerAtStamp(dateTime3.AddSeconds(-1)), EqualTo(serverNameB));
            Expect(System.TryGetServerAtStamp(dateTime3), EqualTo(serverNameC));
            Expect(System.TryGetServerAtStamp(dateTime3.AddSeconds(1)), EqualTo(serverNameC));
        }
开发者ID:imtheman,项目名称:WurmApi,代码行数:30,代码来源:SortedServerHistoryTests.cs

示例6: CreateFakeHistory

        public static void CreateFakeHistory(int positions)
        {
            List<ProcessHistoryDetail> fakeHistory = new List<ProcessHistoryDetail>();
            Random rnd = new Random();
            const int maxSec = 43200; //12h

            DateTime da = new DateTime(2005, 07, 08);
            DateTime db = da.AddSeconds(rnd.Next(maxSec));

            for (int i = 0; i < positions; i++)
            {
                ProcessHistoryDetail t = new ProcessHistoryDetail(da, db);
                fakeHistory.Add(new ProcessHistoryDetail(t));

                da = db.AddSeconds(rnd.Next(maxSec));
                db = da.AddSeconds(rnd.Next(maxSec));
            }

            XmlSerializer fakeSerializer = new XmlSerializer(typeof(List<ProcessHistoryDetail>));

            using (StreamWriter write = new StreamWriter(Path.GetRandomFileName() + ".xml"))
            {
                try
                {
                    fakeSerializer.Serialize(write, fakeHistory);
                }
                catch(IOException)
                {

                }
            }
        }
开发者ID:jiangzhonghui,项目名称:Process-Watch,代码行数:32,代码来源:FakeProcessReport.cs

示例7: GetWeather

        public static async Task<Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key = "YOUR API KEY HERE";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                + zipCode + ",us&appid=" + key + "&units=imperial";

            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind = (string)results["wind"]["speed"] + " mph";
                weather.Humidity = (string)results["main"]["humidity"] + " %";
                weather.Visibility = (string)results["weather"][0]["main"];

                DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset = sunset.ToString() + " UTC";
                return weather;
            }
            else
            {
                return null;
            }
        }
开发者ID:RickySan65,项目名称:xamarin-forms-samples,代码行数:30,代码来源:Core.cs

示例8: CreateReportFile

    static public string CreateReportFile(Contact supplier, DateTime fromDate, DateTime toDate) {
      DataView view = BillingDS.GetBills(fromDate, toDate, "[BillType] IN('B','G') AND [BillStatus] <> 'X' AND " +
                                           "[CancelationTime] > '" + toDate.ToString("yyyy-MM-dd HH:mm:ss") + "'");

      string fileContents = GetReportFileSection(view, "1", "I");   // Active bills

      view = BillingDS.GetBills(DateTime.Parse("31/12/2011"), fromDate.AddSeconds(-0.5),
                                   "[BillType] = 'B' AND [BillStatus] = 'C' AND [CancelationTime] >= '" + fromDate.ToString("yyyy-MM-dd") + "' AND " +
                                   "[CancelationTime] <= '" + toDate.ToString("yyyy-MM-dd HH:mm:ss") + "'");

      fileContents += GetReportFileSection(view, "0", "I");         // Canceled bills

      view = BillingDS.GetBills(fromDate, toDate, "[BillType] IN ('C','L') AND [BillStatus] = 'A'");

      fileContents += GetReportFileSection(view, "1", "E");         // Active credit notes

      view = BillingDS.GetBills(DateTime.Parse("31/12/2011"), fromDate.AddSeconds(-0.5),
                                  "[BillType] IN ('C','L') AND [BillStatus] = 'C' AND [CancelationTime] >= '" + fromDate.ToString("yyyy-MM-dd") + "' AND " +
                                  "[CancelationTime] <= '" + toDate.ToString("yyyy-MM-dd HH:mm:ss") + "'");

      fileContents += GetReportFileSection(view, "0", "E");         // Canceled credit notes

      fileContents = fileContents.TrimEnd(System.Environment.NewLine.ToCharArray());

      string fileName = GetReportFileName(toDate);

      System.IO.File.WriteAllText(fileName, fileContents);

      return fileName;
    }
开发者ID:Ontica,项目名称:Empiria.Trade,代码行数:30,代码来源:XmlBill.cs

示例9: FiresSkippedEventsInSameCallToScan

 public void FiresSkippedEventsInSameCallToScan()
 {
     int count = 0;
     var time = new DateTime(2015, 08, 11, 10, 30, 0);
     var sevent = new ScheduledEvent("test", new[] { time.AddSeconds(-2), time.AddSeconds(-1), time}, (n, t) => count++);
     sevent.Scan(time);
     Assert.AreEqual(3, count);
 }
开发者ID:skyfyl,项目名称:Lean,代码行数:8,代码来源:ScheduledEventTests.cs

示例10: PPItemWorkTime

		/// <summary>
		/// Creates an instance of WorkTimeRangeVm for the given <see cref="Soheil.Model.WorkShift"/>
		/// </summary>
		/// <param name="shift"></param>
		public PPItemWorkTime(WorkShift shift, DateTime dayStart)
		{
			DayStart = dayStart;
			Start = dayStart.AddSeconds(shift.StartSeconds);
			End = dayStart.AddSeconds(shift.EndSeconds);
			Id = shift.Id;
			Model = shift;
		}
开发者ID:T1Easyware,项目名称:Soheil,代码行数:12,代码来源:PPItemWorkTime.cs

示例11: WorkTimeRangeVm

		/// <summary>
		/// Creates an instance of WorkTimeRangeVm for the given <see cref="Soheil.Model.WorkBreak"/>
		/// </summary>
		/// <param name="wbreak"></param>
		protected WorkTimeRangeVm(WorkBreak wbreak, DateTime offset)
		{
			Start = offset.AddSeconds(wbreak.StartSeconds);
			End = offset.AddSeconds(wbreak.EndSeconds);
			Color = DefaultColors.WorkBreak;
			Id = wbreak.Id;
			IsShift = false;
		}
开发者ID:T1Easyware,项目名称:Soheil,代码行数:12,代码来源:WorkTimeRangeVm.cs

示例12: TestMethod6

 public void TestMethod6()
 {
     DateTime Date = new DateTime();
     Methods c = new Methods();
     string d = "Mon";
     string a = "Thu";
     Assert.AreEqual(d,c.TradeStop(Date.AddSeconds(1463674549)));
     Assert.IsFalse(a==c.TradeStop(Date.AddSeconds(1463674549)));
 }
开发者ID:Sank-WoT,项目名称:Forex,代码行数:9,代码来源:UnitTest1.cs

示例13: SkipsEventsUntilTime

 public void SkipsEventsUntilTime()
 {
     int count = 0;
     var time = new DateTime(2015, 08, 11, 10, 30, 0);
     var sevent = new ScheduledEvent("test", new[] { time.AddSeconds(-2), time.AddSeconds(-1), time }, (n, t) => count++);
     // skips all preceding events, not including the specified time
     sevent.SkipEventsUntil(time);
     Assert.AreEqual(time, sevent.NextEventUtcTime);
 }
开发者ID:skyfyl,项目名称:Lean,代码行数:9,代码来源:ScheduledEventTests.cs

示例14: UnixTimeStampToDateTime

 public static DateTime UnixTimeStampToDateTime(double unixTimeStamp, bool localTime)
 {
     // Unix timestamp is seconds past epoch
     DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
     if (localTime)
         dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
     else
         dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToUniversalTime();
     return dtDateTime;
 }
开发者ID:mdefehr,项目名称:QuadrigaCX.NET,代码行数:10,代码来源:Helpers.cs

示例15: IncrementedTimeTest

		public void IncrementedTimeTest()
		{
			DateTime initial = new DateTime(2007, 10, 02, 14, 32, 10);
			Thread.Sleep(100);
            Assert.AreEqual(global::System.Current.DateTime.Now, initial);
            Assert.AreEqual(global::System.Current.DateTime.Now, initial.AddSeconds(1 * 310));
			Thread.Sleep(100);
            Assert.AreEqual(global::System.Current.DateTime.Now, initial.AddSeconds(2 * 310));
            Assert.AreEqual(global::System.Current.DateTime.Now, initial.AddSeconds(3 * 310));
		}
开发者ID:codetuner,项目名称:Arebis.Common,代码行数:10,代码来源:MockTimeAdviceTests.cs


注:本文中的System.DateTime.AddSeconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。