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


C# LocalDateTime类代码示例

本文整理汇总了C#中LocalDateTime的典型用法代码示例。如果您正苦于以下问题:C# LocalDateTime类的具体用法?C# LocalDateTime怎么用?C# LocalDateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ConvertToUtcWithUncpecifiedKind

        /// Returns UTC DateTime with Kind.Unspecified
        public static DateTime ConvertToUtcWithUncpecifiedKind(this DateTime dateTime, string tzFrom) {
            string tz;
            if (!Normalizer.TryGetValue(tzFrom.ToLowerInvariant(), out tz)) {
                tz = tzFrom;
            }
            //tz = tz.ToLowerInvariant();
            if (tz.ToLowerInvariant() == "utc") {
                if (dateTime.Kind == DateTimeKind.Local) throw new ArgumentException("Cannot treat local time as Utc, please specify kind = Utc or Uncpecified");
                return DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified);
            }
            var utcTimeZone = DateTimeZoneProviders.Tzdb["UTC"];
            var givenTz = DateTimeZoneProviders.Tzdb[tz];
            var tickWithinSecond = (int) (dateTime.Ticks%TimeSpan.TicksPerSecond);
            var millis = tickWithinSecond / 10000;
            var tickWithinMillis = tickWithinSecond % 10000;

            var timeToConvert = new LocalDateTime(dateTime.Year,
                    dateTime.Month,
                    dateTime.Day,
                    dateTime.Hour,
                    dateTime.Minute, 
                    dateTime.Second,
                    millis,
                    tickWithinMillis
                ).InZoneStrictly(givenTz); ;
            DateTime utcTime = timeToConvert.ToDateTimeUtc();
            return DateTime.SpecifyKind(utcTime, DateTimeKind.Unspecified);
        }
开发者ID:kevmal,项目名称:Spreads,代码行数:29,代码来源:DateTimeExtensions.cs

示例2: AddFourYearsOnLeapDay

 public void AddFourYearsOnLeapDay()
 {
     LocalDateTime start = new LocalDateTime(2012, 2, 29, 10, 0);
     LocalDateTime result = start + Period.FromYears(4);
     // Feb 29th is still valid in 2016
     Assert.AreEqual(new LocalDateTime(2016, 2, 29, 10, 0), result);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:PeriodAdditionTest.cs

示例3: UnixEpoch

 public void UnixEpoch()
 {
     CalendarSystem coptic = CalendarSystem.GetCopticCalendar(4);
     LocalDateTime unixEpochInCopticCalendar = new LocalDateTime(LocalInstant.LocalUnixEpoch, coptic);
     LocalDateTime expected = new LocalDateTime(1686, 4, 23, 0, 0, coptic);
     Assert.AreEqual(expected, unixEpochInCopticCalendar);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:CopticCalendarSystemTest.cs

示例4: FieldsOf_GreatAchievement

        public void FieldsOf_GreatAchievement()
        {
            LocalDateTime now = new LocalDateTime(new LocalInstant((TimeOfGreatAchievement - UnixEpochDateTime).Ticks), CalendarSystem.Iso);

            Assert.AreEqual(2009, now.Year);
            Assert.AreEqual(2009, now.YearOfEra);
            Assert.AreEqual(9, now.YearOfCentury);
            Assert.AreEqual(20, now.CenturyOfEra);
            Assert.AreEqual(2009, now.WeekYear);
            Assert.AreEqual(48, now.WeekOfWeekYear);
            Assert.AreEqual(11, now.MonthOfYear);
            Assert.AreEqual(27, now.DayOfMonth);
            Assert.AreEqual(TimeOfGreatAchievement.DayOfYear, now.DayOfYear);
            Assert.AreEqual(IsoDayOfWeek.Friday, now.IsoDayOfWeek);
            Assert.AreEqual(5, now.DayOfWeek);
            Assert.AreEqual(Era.Common, now.Era);
            Assert.AreEqual(18, now.HourOfDay);
            Assert.AreEqual(38, now.MinuteOfHour);
            Assert.AreEqual(25, now.SecondOfMinute);
            Assert.AreEqual((18 * 60 * 60) + (38 * 60) + 25, now.SecondOfDay);
            Assert.AreEqual(345, now.MillisecondOfSecond);
            Assert.AreEqual(345 + now.SecondOfDay * 1000, now.MillisecondOfDay);
            Assert.AreEqual(now.MillisecondOfDay * 10000L + 8765, now.TickOfDay);
            Assert.AreEqual(8765, now.TickOfMillisecond);
            Assert.AreEqual(3458765, now.TickOfSecond);
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:26,代码来源:IsoCalendarSystemTest.cs

示例5: EraProperty

 public void EraProperty()
 {
     CalendarSystem calendar = CalendarSystem.Gregorian;
     LocalDateTime startOfEra = new LocalDateTime(1, 1, 1, 0, 0, 0, calendar);
     Assert.AreEqual(Era.Common, startOfEra.Era);
     Assert.AreEqual(Era.BeforeCommon, startOfEra.PlusTicks(-1).Era);
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:GregorianCalendarSystemTest.cs

示例6: SampleDate

        public void SampleDate()
        {
            CalendarSystem copticCalendar = CalendarSystem.GetCopticCalendar(4);
            LocalDateTime iso = new LocalDateTime(2004, 6, 9, 0, 0, 0, 0);
            LocalDateTime coptic = new LocalDateTime(iso.LocalInstant, copticCalendar);

            Assert.AreEqual(Era.AnnoMartyrm, coptic.Era);
            Assert.AreEqual(18, coptic.CenturyOfEra);
            Assert.AreEqual(20, coptic.YearOfCentury);
            Assert.AreEqual(1720, coptic.YearOfEra);

            Assert.AreEqual(1720, coptic.Year);
            Assert.IsFalse(copticCalendar.IsLeapYear(1720));
        
            Assert.AreEqual(10, coptic.MonthOfYear);
            Assert.AreEqual(2, coptic.DayOfMonth);
            
            // TODO: Determine whether we should consider the Coptic calendar to use ISO
            // days of the week.
            Assert.AreEqual(IsoDayOfWeek.Wednesday, coptic.IsoDayOfWeek);

            Assert.AreEqual(9 * 30 + 2, coptic.DayOfYear);

            Assert.AreEqual(0, coptic.HourOfDay);
            Assert.AreEqual(0, coptic.MinuteOfHour);
            Assert.AreEqual(0, coptic.SecondOfMinute);
            Assert.AreEqual(0, coptic.MillisecondOfSecond);
            Assert.AreEqual(0, coptic.TickOfMillisecond);
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:29,代码来源:CopticCalendarSystemTest.cs

示例7: GetOccurrenceForYear_Defaults_Epoch

 public void GetOccurrenceForYear_Defaults_Epoch()
 {
     var offset = new ZoneYearOffset(TransitionMode.Utc, 1, 1, 0, true, LocalTime.Midnight);
     var actual = offset.GetOccurrenceForYear(1970);
     var expected = new LocalDateTime(1970, 1, 1, 0, 0).ToLocalInstant();
     Assert.AreEqual(expected, actual);
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:7,代码来源:ZoneYearOffsetTest.cs

示例8: AddMilliseconds_Arround3Days_AreEqual

        public void AddMilliseconds_Arround3Days_AreEqual()
        {
            var act = TestStruct.AddMilliseconds(3 * 24 * 60 * 60 * 1003);
            var exp = new LocalDateTime(1988, 06, 16, 22, 23, 02, 601);

            Assert.AreEqual(exp, act);
        }
开发者ID:Corniel,项目名称:Qowaiv,代码行数:7,代码来源:LocalDateTimeTest.cs

示例9: AddMinutes_2280_AreEqual

        public void AddMinutes_2280_AreEqual()
        {
            var act = TestStruct.AddMinutes(2 * 24 * 60);
            var exp = new LocalDateTime(1988, 06, 15, 22, 10, 05, 001);

            Assert.AreEqual(exp, act);
        }
开发者ID:Corniel,项目名称:Qowaiv,代码行数:7,代码来源:LocalDateTimeTest.cs

示例10: UnixEpoch

 public void UnixEpoch()
 {
     CalendarSystem coptic = CalendarSystem.Coptic;
     LocalDateTime unixEpochInCopticCalendar = NodaConstants.UnixEpoch.InZone(DateTimeZone.Utc, coptic).LocalDateTime;
     LocalDateTime expected = new LocalDateTime(1686, 4, 23, 0, 0, coptic);
     Assert.AreEqual(expected, unixEpochInCopticCalendar);
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:CopticCalendarSystemTest.cs

示例11: AddHours_41_AreEqual

        public void AddHours_41_AreEqual()
        {
            var act = TestStruct.AddHours(41);
            var exp = new LocalDateTime(1988, 06, 15, 15, 10, 05, 001);

            Assert.AreEqual(exp, act);
        }
开发者ID:Corniel,项目名称:Qowaiv,代码行数:7,代码来源:LocalDateTimeTest.cs

示例12: GetAnswer

 public Answer GetAnswer(Question question)
 {
     var cityToken = question.GetToken<CityToken>();
     var dateToken = question.GetToken<DateToken>();
     int? year = null;
     if (dateToken != null) year = dateToken.Year;
     DaylightSavingInformation daylightSavingInfo;
     if (year.HasValue)
     {
         var firstDateInTheYear = new LocalDateTime(year.Value, 1, 1, 0, 0).InZone(DateTimeZoneProviders.Tzdb[cityToken.City.Timezone], Resolvers.LenientResolver);
         var firstZoneIntervalInTheYear = firstDateInTheYear.GetZoneInterval();
         if (firstZoneIntervalInTheYear.IsoLocalEnd.Year > 10000) {
             daylightSavingInfo = DaylightSavingInformation.CreateWithNoDaylightSavings();
         }
         else
         {
             var firstDateInTheNextZoneInterval = firstDateInTheYear.Plus(firstZoneIntervalInTheYear.Duration).Plus(Duration.FromMilliseconds(1));
             daylightSavingInfo = GetDaylightSavingInfo(firstDateInTheNextZoneInterval);
         }
     }
     else
     {
         daylightSavingInfo = GetDaylightSavingInfo(cityToken.GetCurrentTime());
     }
     var answerText = GetFormattedDaylightSavingInfo(daylightSavingInfo, cityToken.City);
     return new Answer(question, true, true, answerText);
 }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:27,代码来源:WhenDaylightSavingsStartStopInCityQuestionHandler.cs

示例13: AddOneYearOnLeapDay

 public void AddOneYearOnLeapDay()
 {
     LocalDateTime start = new LocalDateTime(2012, 2, 29, 10, 0);
     LocalDateTime result = start + Period.FromYears(1);
     // Feb 29th becomes Feb 28th
     Assert.AreEqual(new LocalDateTime(2013, 2, 28, 10, 0), result);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:PeriodAdditionTest.cs

示例14: FieldsOf_UnixEpoch

        public void FieldsOf_UnixEpoch()
        {
            // It's easiest to test this using a LocalDateTime in the ISO calendar system.
            // LocalDateTime just passes everything through anyway.
            LocalDateTime epoch = new LocalDateTime(LocalInstant.LocalUnixEpoch, CalendarSystem.Iso);

            Assert.AreEqual(1970, epoch.Year);
            Assert.AreEqual(1970, epoch.YearOfEra);
            Assert.AreEqual(70, epoch.YearOfCentury);
            Assert.AreEqual(19, epoch.CenturyOfEra);
            Assert.AreEqual(1970, epoch.WeekYear);
            Assert.AreEqual(1, epoch.WeekOfWeekYear);
            Assert.AreEqual(1, epoch.MonthOfYear);
            Assert.AreEqual(1, epoch.DayOfMonth);
            Assert.AreEqual(1, epoch.DayOfYear);
            Assert.AreEqual(IsoDayOfWeek.Thursday, epoch.IsoDayOfWeek);
            Assert.AreEqual(4, epoch.DayOfWeek);
            Assert.AreEqual(Era.Common, epoch.Era);
            Assert.AreEqual(0, epoch.HourOfDay);
            Assert.AreEqual(0, epoch.MinuteOfHour);
            Assert.AreEqual(0, epoch.SecondOfMinute);
            Assert.AreEqual(0, epoch.SecondOfDay);
            Assert.AreEqual(0, epoch.MillisecondOfSecond);
            Assert.AreEqual(0, epoch.MillisecondOfDay);
            Assert.AreEqual(0, epoch.TickOfDay);
            Assert.AreEqual(0, epoch.TickOfMillisecond);
            Assert.AreEqual(0, epoch.TickOfSecond);
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:28,代码来源:IsoCalendarSystemTest.cs

示例15: Epoch

 public void Epoch()
 {
     LocalDateTime julianEpoch = new LocalDateTime(LocalInstant.LocalUnixEpoch, Julian);
     Assert.AreEqual(1969, julianEpoch.Year);
     Assert.AreEqual(12, julianEpoch.MonthOfYear);
     Assert.AreEqual(19, julianEpoch.DayOfMonth);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:JulianCalendarSystemTest.cs


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