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


C# DateTimeOffset.AddMilliseconds方法代码示例

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


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

示例1: QuickPulseCollectionTimeSlotManagerHandlesFirstHalfOfSecond

        public void QuickPulseCollectionTimeSlotManagerHandlesFirstHalfOfSecond()
        {
            // ARRANGE
            var manager = new QuickPulseCollectionTimeSlotManager();

            var now = new DateTimeOffset(2016, 1, 1, 0, 0, 1, TimeSpan.Zero);
            now = now.AddMilliseconds(499);

            // ACT
            DateTimeOffset slot = manager.GetNextCollectionTimeSlot(now);

            // ASSERT
            Assert.AreEqual(now.AddMilliseconds(1), slot);
        }
开发者ID:xornand,项目名称:ApplicationInsights-dotnet-server,代码行数:14,代码来源:QuickPulseCollectionTimeSlotManagerTests.cs

示例2: SortingFinelyDifferentDateTimes

        public void SortingFinelyDifferentDateTimes()
        {
            using (var transaction = _realm.BeginWrite())
            {
                foreach (var ms in new int[] { 10, 999, 998, 42 })
                {
                    var birthday = new DateTimeOffset(1912, 6, 23, 23, 59, 59, ms, TimeSpan.Zero);
                    foreach (var addMs in new double[] { -2000.0, 1.0, -1.0, 1000.0, 100.0 })
                    {
                        _realm.Add(new Person { Birthday = birthday.AddMilliseconds(addMs) });
                    }
                }

                transaction.Commit();
            }

            // Assert
            var sortedTurings = _realm.All<Person>().OrderBy(p => p.Birthday);
            var prevB = new DateTimeOffset();
            foreach (var t in sortedTurings)
            {
                Assert.That(t.Birthday, Is.GreaterThan(prevB));
                prevB = t.Birthday;
            }
        }
开发者ID:realm,项目名称:realm-dotnet,代码行数:25,代码来源:DateTimeTests.cs

示例3: ToDateTime

        public static DateTime ToDateTime(this long value)
        {
            var dateTime = new DateTimeOffset(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));
            dateTime = dateTime.AddMilliseconds(value);

            return dateTime.UtcDateTime;
        }
开发者ID:AppSpaceIT,项目名称:PaylevenWebAppSharp,代码行数:7,代码来源:Extensions.cs

示例4: RoundsToNearestSecond

        public void RoundsToNearestSecond()
        {
            var now = new DateTimeOffset(2015, 03, 04, 20, 07, 21, TimeSpan.Zero);

            var testDto1 = now.AddMilliseconds(450);
            var actualDto1 = testDto1.RoundToNearestSecond();

            Assert.AreEqual(now, actualDto1);
            TestHelper.AssertSerialiseEqual(now, actualDto1);

            var expectedDto2 = now.AddSeconds(1);
            var testDto2 = now.AddMilliseconds(550);
            var actualDto2 = testDto2.RoundToNearestSecond();

            Assert.AreEqual(expectedDto2, actualDto2);
            TestHelper.AssertSerialiseEqual(expectedDto2, actualDto2);
        }
开发者ID:roberdjp,项目名称:lastfm,代码行数:17,代码来源:TestHelperTests.cs

示例5: GetNextSchedule

        public DateTimeOffset GetNextSchedule(DateTimeOffset withinThisMinute)
        {
            Contract.Requires(null != withinThisMinute);
            Contract.Ensures(null != Contract.Result<DateTimeOffset>());

            // we only add a millisecond as we get exceptions on certain Windows versions 
            // while converting DateTime to DateTimeOffset
            // see https://support.microsoft.com/en-us/kb/2346777 for details

            if(0 == withinThisMinute.Millisecond)
            {
                withinThisMinute = withinThisMinute.AddMilliseconds(1);
            }

            //Test Name:	IsScheduledToRunOnTheMinuteReturnsTrue
            //Test Outcome:	Failed
            //Result Message:	
            //Test method biz.dfch.CS.Appclusive.Scheduler.Core.Tests.ScheduledJobSchedulerTest.IsScheduledToRunOnTheMinuteReturnsTrue threw exception: 
            //System.ArgumentOutOfRangeException: The UTC time represented when the offset is applied must be between year 0 and 10,000.
            //Parameter name: offset
            //Result StandardOutput:	
            //2019-04-13 20:00:00,000|ERROR|[email protected]: 'The UTC time represented when the offset is applied must be between year 0 and 10,000.
            //Parameter name: offset'
            //[The UTC time represented when the offset is applied must be between year 0 and 10,000.
            //Parameter name: offset]
            //   at System.DateTimeOffset.ValidateDate(DateTime dateTime, TimeSpan offset)
            //   at System.DateTimeOffset..ctor(DateTime dateTime, TimeSpan offset)
            //   at biz.dfch.CS.Appclusive.Scheduler.Core.ScheduledJobScheduler.GetNextSchedule(DateTimeOffset withinThisMinute) 
            // in c:\Github\biz.dfch.CS.Appclusive.Scheduler\src\biz.dfch.CS.Appclusive.Scheduler.Core\ScheduledJobScheduler.cs:line 86

            try
            {
                var nextSchedule = DateTimeOffset.MinValue;

                if (IsCrontabExpression())
                {
                    nextSchedule = GetNextScheduleFromCrontabExpression(withinThisMinute);
                }
                else if(IsQuartzExpression())
                {
                    nextSchedule = GetNextScheduleFromQuartzExpression(withinThisMinute);
                }
                else
                {
                    Trace.WriteLine("JobId '{0}': invalid Crontab or Quartz expression '{1}'", this.job.Id, job.Crontab);
                }

                return nextSchedule;
            }
            catch (Exception ex)
            {
                var message = string.Format("JobId '{0}': {1}", this.job.Id, ex.Message);
                Trace.WriteException(message, ex);

                throw;
            }
        }
开发者ID:dfensgmbh,项目名称:biz.dfch.CS.Appclusive.Scheduler,代码行数:57,代码来源:ScheduledJobScheduler.cs

示例6: CanAddMillisecondsAcrossDstTransition

        public void CanAddMillisecondsAcrossDstTransition()
        {
            var tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dto = new DateTimeOffset(2015, 3, 8, 1, 59, 59, 999, TimeSpan.FromHours(-8));
            var result = dto.AddMilliseconds(1, tz);

            var expected = new DateTimeOffset(2015, 3, 8, 3, 0, 0, TimeSpan.FromHours(-7));
            Assert.Equal(expected, result);
            Assert.Equal(expected.Offset, result.Offset);
        }
开发者ID:kronic,项目名称:corefxlab,代码行数:10,代码来源:DateTimeOffsetTests.cs

示例7: AppendToExistingHDF5

        public void AppendToExistingHDF5()
        {
            if (File.Exists("AppendToExistingHDF5.h5"))
                File.Delete("AppendToExistingHDF5.h5");

            Epoch e1;
            Epoch e2;

            using (var persistor = H5EpochPersistor.Create("AppendToExistingHDF5.h5"))
            {
                var time = new DateTimeOffset(2011, 8, 22, 11, 12, 0, 0, TimeSpan.FromHours(-6));

                var src = persistor.AddSource("source1", null);
                persistor.BeginEpochGroup("label1", src, time);

                e1 = RunSingleEpoch(5000, 2, persistor);
                persistor.EndEpochGroup(time.AddMilliseconds(100));

                persistor.Close();
            }

            using (var persistor = new H5EpochPersistor("AppendToExistingHDF5.h5"))
            {
                var time = new DateTimeOffset(2011, 8, 22, 11, 12, 0, 0, TimeSpan.FromHours(-6));

                var src = persistor.AddSource("source2", null);
                persistor.BeginEpochGroup("label2", src, time);

                e2 = RunSingleEpoch(5000, 2, persistor);
                persistor.EndEpochGroup(time.AddMilliseconds(100));

                persistor.Close();
            }

            using (var persistor = new H5EpochPersistor("AppendToExistingHDF5.h5"))
            {
                Assert.AreEqual(2, persistor.Experiment.EpochGroups.Count());

                var eg1 = persistor.Experiment.EpochGroups.First(g => g.Label == "label1");

                Assert.AreEqual(1, eg1.EpochBlocks.Count());
                Assert.AreEqual(1, eg1.EpochBlocks.First().Epochs.Count());
                PersistentEpochAssert.AssertEpochsEqual(e1, eg1.EpochBlocks.First().Epochs.First());

                var eg2 = persistor.Experiment.EpochGroups.First(g => g.Label == "label2");

                Assert.AreEqual(1, eg2.EpochBlocks.Count());
                Assert.AreEqual(1, eg2.EpochBlocks.First().Epochs.Count());
                PersistentEpochAssert.AssertEpochsEqual(e2, eg2.EpochBlocks.First().Epochs.First());
            }
        }
开发者ID:Symphony-DAS,项目名称:symphony-core,代码行数:51,代码来源:SimulationIntegration.cs

示例8: TestAddition

    public static void TestAddition()
    {
        DateTimeOffset dt = new DateTimeOffset(new DateTime(1986, 8, 15, 10, 20, 5, 70));
        Assert.Equal(17, dt.AddDays(2).Day);
        Assert.Equal(13, dt.AddDays(-2).Day);

        Assert.Equal(10, dt.AddMonths(2).Month);
        Assert.Equal(6, dt.AddMonths(-2).Month);

        Assert.Equal(1996, dt.AddYears(10).Year);
        Assert.Equal(1976, dt.AddYears(-10).Year);

        Assert.Equal(13, dt.AddHours(3).Hour);
        Assert.Equal(7, dt.AddHours(-3).Hour);

        Assert.Equal(25, dt.AddMinutes(5).Minute);
        Assert.Equal(15, dt.AddMinutes(-5).Minute);

        Assert.Equal(35, dt.AddSeconds(30).Second);
        Assert.Equal(2, dt.AddSeconds(-3).Second);

        Assert.Equal(80, dt.AddMilliseconds(10).Millisecond);
        Assert.Equal(60, dt.AddMilliseconds(-10).Millisecond);
    }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:24,代码来源:DateTimeOffset.cs

示例9: From_FromFixedDateTime_Tests

    public void From_FromFixedDateTime_Tests(int value)
    {
        var originalPointInTime = new DateTimeOffset(1976, 12, 31, 17, 0, 0, 0, TimeSpan.Zero);

        Assert.AreEqual(value.Years().From(originalPointInTime), originalPointInTime.AddYears(value));
        Assert.AreEqual(value.Months().From(originalPointInTime), originalPointInTime.AddMonths(value));
        Assert.AreEqual(value.Weeks().From(originalPointInTime), originalPointInTime.AddDays(value*DaysPerWeek));
        Assert.AreEqual(value.Days().From(originalPointInTime), originalPointInTime.AddDays(value));

        Assert.AreEqual(value.Hours().From(originalPointInTime), originalPointInTime.AddHours(value));
        Assert.AreEqual(value.Minutes().From(originalPointInTime), originalPointInTime.AddMinutes(value));
        Assert.AreEqual(value.Seconds().From(originalPointInTime), originalPointInTime.AddSeconds(value));
        Assert.AreEqual(value.Milliseconds().From(originalPointInTime), originalPointInTime.AddMilliseconds(value));
        Assert.AreEqual(value.Ticks().From(originalPointInTime), originalPointInTime.AddTicks(value));
    }
开发者ID:jin29neci,项目名称:FluentDateTime,代码行数:15,代码来源:DateTimeOffsetTests.cs

示例10: GetNextIncludedTimeUtc

        /// <summary>
        /// Determine the next time that is 'included' by the
        /// Calendar after the given time. Return the original value if timeStamp is
        /// included. Return 0 if all days are excluded.
        /// </summary>
        /// <param name="timeUtc"></param>
        /// <returns></returns>
        public override DateTimeOffset GetNextIncludedTimeUtc(DateTimeOffset timeUtc)
        {
            DateTimeOffset nextIncludedTime = timeUtc.AddMilliseconds(1); //plus on millisecond

            while (!IsTimeIncluded(nextIncludedTime))
            {
                //If the time is in a range excluded by this calendar, we can
                // move to the end of the excluded time range and continue testing
                // from there. Otherwise, if nextIncludedTime is excluded by the
                // baseCalendar, ask it the next time it includes and begin testing
                // from there. Failing this, add one millisecond and continue
                // testing.
                if (cronExpression.IsSatisfiedBy(nextIncludedTime))
                {
                    nextIncludedTime = cronExpression.GetNextValidTimeAfter(nextIncludedTime).Value;
                }
                else if ((GetBaseCalendar() != null) &&
                         (!GetBaseCalendar().IsTimeIncluded(nextIncludedTime)))
                {
                    nextIncludedTime =
                        GetBaseCalendar().GetNextIncludedTimeUtc(nextIncludedTime);
                }
                else
                {
                    nextIncludedTime = nextIncludedTime.AddMilliseconds(1);
                }
            }

            return nextIncludedTime;
        }
开发者ID:vaskosound,项目名称:FantasyLeagueStats,代码行数:37,代码来源:CronCalendar.cs

示例11: EpochMillisecondsToDateTime

 /// <summary>
 /// Datetime from an int representing a unix epoch time
 /// </summary>
 /// <param name="msSinceEpoch"></param>
 /// <returns></returns>
 public static DateTimeOffset EpochMillisecondsToDateTime(this long msSinceEpoch)
 {
     var date = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
     return date.AddMilliseconds(msSinceEpoch);
 }
开发者ID:orianbsilva,项目名称:kafka4net,代码行数:10,代码来源:DateTimeExtensions.cs

示例12: Expired_Reference_Token

        public async Task Expired_Reference_Token()
        {
            now = DateTimeOffset.UtcNow;

            var store = new InMemoryTokenHandleStore();
            var validator = Factory.CreateTokenValidator(store);

            var token = TokenFactory.CreateAccessToken(new Client { ClientId = "roclient" }, "valid", 2, "read", "write");
            var handle = "123";

            await store.StoreAsync(handle, token);
            
            now = now.AddMilliseconds(2000);

            var result = await validator.ValidateAccessTokenAsync("123");

            result.IsError.Should().BeTrue();
            result.Error.Should().Be(Constants.ProtectedResourceErrors.ExpiredToken);
        }
开发者ID:rbottieri,项目名称:IdentityServer3,代码行数:19,代码来源:AccessTokenValidation.cs

示例13: AddMilliseconds

 public static void AddMilliseconds(DateTimeOffset dateTimeOffset, double milliseconds, DateTimeOffset expected)
 {
     Assert.Equal(expected, dateTimeOffset.AddMilliseconds(milliseconds));
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:4,代码来源:DateTimeOffsetTests.cs

示例14: ConvertFromJsTimestamp

 public static DateTimeOffset ConvertFromJsTimestamp(long timestamp)
 {
     DateTimeOffset origin = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, DateTimeOffset.Now.Offset);
     return origin.AddMilliseconds(timestamp);
 }
开发者ID:prabhakara,项目名称:Dexter-Blog-Engine,代码行数:5,代码来源:DateTimeOffsetUtil.cs

示例15: FindingByMilliseconds

        public void FindingByMilliseconds()
        {
            var birthday = new DateTimeOffset(1912, 6, 23, 23, 59, 59, 0, TimeSpan.Zero);
            using (var transaction = _realm.BeginWrite())
            {
                foreach (var addMs in new double[] { 0.0, 1.0, -1.0 })
                {
                    _realm.Add(new Person { Birthday = birthday.AddMilliseconds(addMs) });
                }

                transaction.Commit();
            }

            // Assert
            Assert.That(_realm.All<Person>().Count(p => p.Birthday < birthday), Is.EqualTo(1));
            Assert.That(_realm.All<Person>().Count(p => p.Birthday == birthday), Is.EqualTo(1));
            Assert.That(_realm.All<Person>().Count(p => p.Birthday >= birthday), Is.EqualTo(2));
            Assert.That(_realm.All<Person>().Count(p => p.Birthday > birthday), Is.EqualTo(1));
        }
开发者ID:realm,项目名称:realm-dotnet,代码行数:19,代码来源:DateTimeTests.cs


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