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


C# this.AddTicks方法代码示例

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


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

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

示例2: TruncateTo

		public static DateTime TruncateTo(this DateTime dateTime, TimeSpan timeSpan)
		{

			if (timeSpan == TimeSpan.Zero) return dateTime; 

			return dateTime.AddTicks(-(dateTime.Ticks % timeSpan.Ticks));
		}
开发者ID:chumakov-ilya,项目名称:PingWin,代码行数:7,代码来源:DateTime.cs

示例3: Truncate

        public static DateTime Truncate(this DateTime dateTime, TimeSpan timeSpan)
        {
            if (timeSpan == TimeSpan.Zero)
                return dateTime;

            return DateTime.SpecifyKind(dateTime.AddTicks(-(dateTime.Ticks % timeSpan.Ticks)), dateTime.Kind);
        }
开发者ID:DanielCruz4th,项目名称:xocsatt,代码行数:7,代码来源:DateTimeExtensions.cs

示例4: RoundDown

 /// <summary>
 /// Extension method to round a datetime down by a timespan interval.
 /// </summary>
 /// <param name="dateTime">Base DateTime object we're rounding down.</param>
 /// <param name="interval">Timespan interval to round to.</param>
 /// <returns>Rounded datetime</returns>
 public static DateTime RoundDown(this DateTime dateTime, TimeSpan interval)
 {
     if (interval == TimeSpan.Zero)
     {
         // divide by zero exception
         return dateTime;
     }
     return dateTime.AddTicks(-(dateTime.Ticks % interval.Ticks));
 }
开发者ID:rchien,项目名称:ToolBox,代码行数:15,代码来源:Extensions.cs

示例5: Add

 /// <summary>
 /// Adds a generic AddType to a DateTime object
 /// </summary>
 /// <param name="now"><seealso cref="System.DateTime"/></param>
 /// <param name="adder">Type structure that acts as a switcher for what type of add to perform</param>
 /// <param name="much">How much AddType to add to each element for creating list of data</param>
 /// <returns>A DateTime object with the added AddType amounts</returns>
 public static DateTime Add(this DateTime now, AddType adder, double much)
 {
     DateTime ret = now;
     switch (adder)
     {
         case AddType.Years:
             {
                 ret = now.AddYears((int)much);
                 break;
             }
         case AddType.Months:
             {
                 ret = now.AddMonths((int)much);
                 break;
             }
         case AddType.Days:
             {
                 ret = now.AddDays(much);
                 break;
             }
         case AddType.Hours:
             {
                 ret = now.AddHours(much);
                 break;
             }
         case AddType.Minutes:
             {
                 ret = now.AddMinutes(much);
                 break;
             }
         case AddType.Seconds:
             {
                 ret = now.AddSeconds(much);
                 break;
             }
         case AddType.Milliseconds:
             {
                 ret = now.AddMilliseconds(much);
                 break;
             }
         case AddType.Ticks:
             {
                 ret = now.AddTicks((long)much);
                 break;
             }
     }
     return ret;
 }
开发者ID:kLeZ,项目名称:Gecko,代码行数:55,代码来源:Extensions.cs

示例6: AddMicroseconds

        /// <summary>
        /// Returns a new DateTime that adds the specified number of microseconds to the value of this instance.
        /// </summary>
        /// <param name="dateTime">The DateTime to add microseconds to.</param>
        /// <param name="value">A number of whole and fractional microseconds. The value parameter can be negative or positive. Note that this value is rounded to the nearest integer.</param>
        /// <returns>An object whose value is the sum of the date and time represented by this instance and the number of microseconds represented by value.</returns>
        public static DateTime AddMicroseconds(this DateTime dateTime, double value)
        {
            const long MaxValue = long.MaxValue / TimeSpanExtensions.TicksPerMicrosecond;
            if (value > MaxValue)
            {
                throw new ArgumentOutOfRangeException("value", value,
                                                      string.Format(CultureInfo.InvariantCulture, "Value cannot be bigger than {0}", MaxValue));
            }

            const long MinValue = long.MinValue / TimeSpanExtensions.TicksPerMicrosecond;
            if (value < MinValue)
            {
                throw new ArgumentOutOfRangeException("value", value,
                                                      string.Format(CultureInfo.InvariantCulture, "Value cannot be smaller than {0}", MinValue));
            }

            long roundedValue = (long)Math.Round(value);
            long ticks = roundedValue * TimeSpanExtensions.TicksPerMicrosecond;
            return dateTime.AddTicks(ticks);
        }
开发者ID:amitla,项目名称:Pcap.Net,代码行数:26,代码来源:DateTimeExtensions.cs

示例7: SubtractTicks

        public static DateTime SubtractTicks(this DateTime date, long value) {
            if (value < 0)
                throw new ArgumentException("Value cannot be less than 0.", "value");

            return date.AddTicks(value * -1);
        }
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:6,代码来源:DateTimeExtensions.cs

示例8: AddMicroseconds

 internal static DateTime AddMicroseconds(this DateTime self, int microseconds)
 {
     return self.AddTicks(microseconds * ticksPerMicrosecond);
 }
开发者ID:Particular,项目名称:NServiceBus,代码行数:4,代码来源:DateTimeExtensions.cs

示例9: RetrieveYesterdayDate

 /// <summary>
 /// Retrieves the yesterday date.
 /// </summary>
 /// <param name="today">The today.</param>
 /// <returns>yesterday date</returns>
 public static DateTime RetrieveYesterdayDate(this DateTime today)
 {
     DateTime yesterdayDate = today.AddTicks(-1);
     return yesterdayDate;
 }
开发者ID:JaipurAnkita,项目名称:mastercode,代码行数:10,代码来源:DateTimeExtensions.cs

示例10: Round

 /// <summary>
 /// Round the given DateTime object by the given time interval. i.e. 10:09 rounded by 10 minutes would be 10:10
 /// </summary>
 /// <param name="dt">The given DateTime object</param>
 /// <param name="interval">The time interval to round by</param>
 /// <returns>The new rounded DateTime object</returns>
 public static DateTime Round(this DateTime dt, TimeSpan interval)
 {
     var halfIntervalTicks = ((interval.Ticks + 1) >> 1);
       return dt.AddTicks(halfIntervalTicks - ((dt.Ticks + halfIntervalTicks) % interval.Ticks));
 }
开发者ID:jbasinger,项目名称:DateTimeExtensions,代码行数:11,代码来源:GeneralDateTimeExtensions.cs

示例11: Floor

 /// <summary>
 /// Floor the given DateTime object by the given time interval. i.e. 10:09 floored by 10 minutes would be 10:00
 /// </summary>
 /// <param name="dt">The given DateTime object</param>
 /// <param name="interval">The time interval to floor by</param>
 /// <returns>The new floored DateTime object</returns>
 public static DateTime Floor(this DateTime dt, TimeSpan interval)
 {
     return dt.AddTicks(-(dt.Ticks % interval.Ticks));
 }
开发者ID:jbasinger,项目名称:DateTimeExtensions,代码行数:10,代码来源:GeneralDateTimeExtensions.cs

示例12: TruncSeconds

		public static DateTime TruncSeconds(this DateTime dateTime)
		{
			return dateTime.AddTicks(-dateTime.Ticks % 600000000);
		}
开发者ID:HackerDom,项目名称:ructfe-2015,代码行数:4,代码来源:DateTimeUtils.cs

示例13: TruncateMilliseconds

        public static DateTimeOffset TruncateMilliseconds(this DateTimeOffset dto)
        {
            // From http://stackoverflow.com/a/1005222/335418

            return dto.AddTicks( - (dto.Ticks % TimeSpan.TicksPerSecond));
        }
开发者ID:PKRoma,项目名称:libgit2sharp,代码行数:6,代码来源:DateTimeOffsetExtensions.cs

示例14: ToSaml2DateTimeString

 public static string ToSaml2DateTimeString(this DateTime dateTime)
 {
     return XmlConvert.ToString(dateTime.AddTicks(-(dateTime.Ticks % TimeSpan.TicksPerSecond)),
         XmlDateTimeSerializationMode.Utc);
 }
开发者ID:arvinsuresh,项目名称:authservices,代码行数:5,代码来源:DateTimeExtensions.cs

示例15: SubtractTicks

 public static DateTime SubtractTicks(this DateTime dateTime, long ticks)
 {
     return dateTime.AddTicks(-ticks);
 }
开发者ID:JonasSamuelsson,项目名称:Handyman,代码行数:4,代码来源:DateTimeExtensions.cs


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