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


C# DateTime.AddTicks方法代码示例

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


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

示例1: GenerateFilterCondition

        public static string GenerateFilterCondition(QueryDateChronologicalComparisons comparison, DateTime date)
        {
            var key = "";
            var queryComparison = QueryComparisons.Equal;

            switch (comparison)
            {
                case QueryDateChronologicalComparisons.After:
                    key = RowKey.CreateChronologicalKeyStart(date.AddTicks(1));
                    queryComparison = QueryComparisons.GreaterThan;
                    break;
                case QueryDateChronologicalComparisons.AfterOrEqual:
                    key = RowKey.CreateChronologicalKeyStart(date);
                    queryComparison = QueryComparisons.GreaterThan;
                    break;
                case QueryDateChronologicalComparisons.Before:
                    queryComparison = QueryComparisons.LessThan;
                    key = RowKey.CreateChronologicalKeyStart(date);
                    break;
                case QueryDateChronologicalComparisons.BeforeOrEqual:
                    queryComparison = QueryComparisons.LessThan;
                    key = RowKey.CreateChronologicalKeyStart(date.AddTicks(1));
                    break;
                default:
                    break;
            }

            return TableQuery.GenerateFilterCondition("RowKey", queryComparison, key);
        }
开发者ID:sandrinodimattia,项目名称:WindowsAzure-ChronoTableStorage,代码行数:29,代码来源:ChronologicalTableQuery.cs

示例2: Add

 public static DateTime Add(DatePartType datePart, long add, DateTime dt)
 {
     switch (datePart) {
     case DatePartType.Year:
         return dt.AddYears ((int)add);
     case DatePartType.Quarter:
         return dt.AddMonths ((int)add * 3);
     case DatePartType.Month:
         return dt.AddMonths ((int)add);
     case DatePartType.Day:
     case DatePartType.DayOfYear:
     case DatePartType.DayOfWeek:
         return dt.AddDays (add);
     case DatePartType.Hour:
         return dt.AddHours (add);
     case DatePartType.Minute:
         return dt.AddMinutes (add);
     case DatePartType.Second:
         return dt.AddSeconds (add);
     case DatePartType.MilliSecond:
         return dt.AddMilliseconds (add);
     case DatePartType.MicroSecond:
         return dt.AddTicks (add * TimeSpan.TicksPerMillisecond / 1000);
     case DatePartType.NanoSecond:
         return dt.AddTicks (add * TimeSpan.TicksPerMillisecond / 1000000);
     default:
         throw new InvalidOperationException (string.Format ("Unknown DatePart type '{0}'", datePart));
     }
 }
开发者ID:WimObiwan,项目名称:FxGqlC,代码行数:29,代码来源:DateFunctionsHelper.cs

示例3: GetNextOcurrence

 public DateTime? GetNextOcurrence(DateTime dateTime)
 {
     if (dateTime.TimeOfDay < FirstTime)
     {
         return dateTime.Date.AddTicks(FirstTime.Ticks);
     }
     else if (dateTime.TimeOfDay >= FirstTime && dateTime.AddTicks(1).TimeOfDay <= SecondTime) return dateTime.AddTicks(1);
     else return null;
 }
开发者ID:nesohc,项目名称:ballin-ninja,代码行数:9,代码来源:TimeRange.cs

示例4: RandomDate

 public static DateTime RandomDate(DateTime from, DateTime to)
 {
     lock ( syncLock )
     {
         return from.AddTicks ((long) ( random.NextDouble () * ( to.Ticks - from.Ticks ) ));
     }
 }
开发者ID:AdysTech,项目名称:InfluxDB.Client.Net,代码行数:7,代码来源:DataGen.cs

示例5: ShouldMatch

		public static void ShouldMatch(this DateTime actual, DateTime expected)
		{
			actual = actual.AddTicks(-(actual.Ticks % TimeSpan.TicksPerMillisecond));
			expected = expected.AddTicks(-(expected.Ticks % TimeSpan.TicksPerMillisecond));

			ShouldBeTestExtensions.ShouldBe(actual, expected);
		}
开发者ID:Pondidum,项目名称:Ledger.Stores.Postgres,代码行数:7,代码来源:Extensions.cs

示例6: 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

示例7: TestConvertToSysTime

        public void TestConvertToSysTime()
        {
            long ticksInMinute = (long)60 * 10000000;
            DateTime utc1601_1_1 = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            DateTime rawNow = DateTime.Now;
            DateTime now = new DateTime(rawNow.Year,
                                        rawNow.Month,
                                        rawNow.Day,
                                        rawNow.Hour,
                                        rawNow.Minute,
                                        0,
                                        0,
                                        rawNow.Kind);
            int prevSysTime = FreeBusyConverter.ConvertToSysTime(now) - 1;

            for (int i = 0; i < 60 * 24 * 368; i++)
            {
                DateTime future = now.AddTicks(i * ticksInMinute);
                int sysTime = FreeBusyConverter.ConvertToSysTime(future);
                DateTime check = utc1601_1_1.AddTicks(sysTime * ticksInMinute);

                Assert.AreEqual(future, check);
                Assert.AreEqual(prevSysTime + 1, sysTime);

                prevSysTime++;
            }
        }
开发者ID:pkdevboxy,项目名称:calendar-connectors,代码行数:27,代码来源:FreeBusyConverterTest.cs

示例8: ParseDateTime

        /// <summary>
        /// Parse the given string representation into a <see cref="DateTime"/> value.
        /// </summary>
        /// <param name="value">A string representation of a date time.</param>
        /// <returns>A <see cref="DateTime"/> value.</returns>
        public DateTime ParseDateTime(string value)
        {
            int year, month, day, hour, minute, second, offsetHours, offsetMinutes;
            long ticks;
            DateTimeKind dateTimeKind;

            GetDateTimeComponents(value, out year, out month, out day, out hour, out minute, out second, out ticks, out offsetHours, out offsetMinutes, out dateTimeKind);

            var toLocal = false;

            if (dateTimeKind == DateTimeKind.Local)
            {
                hour -= offsetHours;
                minute -= offsetMinutes;

                Adjust(ref year, ref month, ref day, ref hour, ref minute);

                dateTimeKind = DateTimeKind.Utc;
                toLocal = true;
            }

            var dateTime = new DateTime(year, month, day, hour, minute, second, dateTimeKind);
            dateTime = dateTime.AddTicks(ticks);

            if (toLocal)
            {
                dateTime = dateTime.ToLocalTime();
            }

            return dateTime;
        }
开发者ID:QuickenLoans,项目名称:XSerializer,代码行数:36,代码来源:DefaultDateTimeHandler.cs

示例9: ProcessLogMessages

        /// <summary>
        /// Processes the log messages.
        /// </summary>
        /// <param name="events">The events to process.</param>
        public void ProcessLogMessages(NLogEvents events)
        {
            var baseTimeUtc = new DateTime(events.BaseTimeUtc, DateTimeKind.Utc);
            var logEvents = new LogEventInfo[events.Events.Length];

            // convert transport representation of log events into workable LogEventInfo[]
            for (int j = 0; j < events.Events.Length; ++j)
            {
                var ev = events.Events[j];
                LogLevel level = LogLevel.FromOrdinal(ev.LevelOrdinal);
                string loggerName = events.Strings[ev.LoggerOrdinal];

                var logEventInfo = new LogEventInfo();
                logEventInfo.Level = level;
                logEventInfo.LoggerName = loggerName;
                logEventInfo.TimeStamp = baseTimeUtc.AddTicks(ev.TimeDelta);
                logEventInfo.Message = events.Strings[ev.MessageOrdinal];
                logEventInfo.Properties.Add("ClientName", events.ClientName);
                for (int i = 0; i < events.LayoutNames.Count; ++i)
                {
                    logEventInfo.Properties.Add(events.LayoutNames[i], ev.Values[i]);
                }

                logEvents[j] = logEventInfo;
            }

            this.ProcessLogMessages(logEvents);
        }
开发者ID:semirs,项目名称:CellAO,代码行数:32,代码来源:LogReceiverForwardingService.cs

示例10: ToDouble

 public static Double ToDouble(DateTime dateTime, TimeZoneKind timezoneKind)
 {
     dateTime = dateTime.AddMilliseconds(-1 * dateTime.Millisecond);
     var timezoneInfo = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneKindDictionary[timezoneKind]);
     var target = dateTime.AddTicks(-1 * timezoneInfo.BaseUtcOffset.Ticks);
     var timespan = new TimeSpan(target.Ticks - UnixEpoch.Ticks);
     return timespan.TotalMilliseconds;
 }
开发者ID:Wahooneko,项目名称:CaveTalk,代码行数:8,代码来源:JavaScriptTime.cs

示例11: FromUnixTicks

        /// <summary>
        /// Converts a JavaScript Date object to a C# DateTime.
        /// </summary>
        /// <param name="unixTicks">JavaScript date ticks.</param>
        /// <returns>Converted C# DateTime.</returns>
        /// <see href="http://renditionprotocol.blogspot.com/2013/08/convert-javascript-epoch-milliseconds.html"/>
        internal static DateTime FromUnixTicks(Double unixTicks)
        {
            DateTime _01jan1970 = new DateTime(1970, 1, 1);

            DateTime convertedDT = _01jan1970.AddTicks(Convert.ToInt64(unixTicks) * 10000);

            return convertedDT;
        }
开发者ID:ChristopherJCavage,项目名称:MooseBox,代码行数:14,代码来源:ExtensionMethods.cs

示例12: ToString

 public override string ToString()
 {
     DateTime time = new DateTime(1970, 01, 01, 0, 0, 0, 0);
     time = time.AddTicks((Eid * 1000) / 100);
     // time.ToLocalTime();
     if (Format)
         return time.ToString("hh:mm") + " " + From + " : " + Text;
     return time.ToString("hh:mm") + " " + Text;
 }
开发者ID:headswe,项目名称:irccloudNET,代码行数:9,代码来源:Message.cs

示例13: PrescriptionHasEnded_False_FakeClock

        public void PrescriptionHasEnded_False_FakeClock()
        {
            DateTime expiry = new DateTime(2012, 1, 1, 0, 0, 0);
            FakeClock clock = new FakeClock(expiry.AddTicks(-1));
            Drug drug = new Drug("Ibuprophen");

            Prescription prescription = new Prescription(expiry, clock, drug);

            Assert.That(prescription.HasExpired, Is.False);
        }
开发者ID:ADThomsen,项目名称:PatternPlayground,代码行数:10,代码来源:PrescriptionTests.cs

示例14: MarketHours

 /// <summary>
 /// Market hours initializer given an hours since midnight measure for the market hours today
 /// </summary>
 /// <param name="referenceDate">Reference date used for as base date from the specified hour offsets</param>
 /// <param name="defaultStart">Time in hours since midnight to start this open period.</param>
 /// <param name="defaultEnd">Time in hours since midnight to end this open period.</param>
 public MarketHours(DateTime referenceDate, double defaultStart, double defaultEnd)
 {
     Start = referenceDate.Date.AddHours(defaultStart);
     End = referenceDate.Date.AddHours(defaultEnd);
     if (defaultEnd == 24)
     {
         // when we mark it as the end of the day other code that relies on .TimeOfDay has issues
         End = End.AddTicks(-1);
     }
 }
开发者ID:reddream,项目名称:Lean,代码行数:16,代码来源:MarketTodayPacket.cs

示例15: TestAddTicks

        public static void TestAddTicks()
        {
            DateTime dt = new DateTime(2001, 1, 1);
            dt = dt.AddTicks(20000000);

            Assert.AreEqual(dt.Year, 2001, "Bridge582 TestAddTicks Year");
            Assert.AreEqual(dt.Month, 1, "Bridge582 TestAddTicks Month");
            Assert.AreEqual(dt.Day, 1, "Bridge582 TestAddTicks Day");
            Assert.AreEqual(dt.Hour, 0, "Bridge582 TestAddTicks Hour");
            Assert.AreEqual(dt.Minute, 0, "Bridge582 TestAddTicks Minute");
            Assert.AreEqual(dt.Second, 2, "Bridge582 TestAddTicks Second");
        }
开发者ID:TinkerWorX,项目名称:Bridge,代码行数:12,代码来源:N582.cs


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