本文整理汇总了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);
}
示例2: TruncateTo
public static DateTime TruncateTo(this DateTime dateTime, TimeSpan timeSpan)
{
if (timeSpan == TimeSpan.Zero) return dateTime;
return dateTime.AddTicks(-(dateTime.Ticks % timeSpan.Ticks));
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例8: AddMicroseconds
internal static DateTime AddMicroseconds(this DateTime self, int microseconds)
{
return self.AddTicks(microseconds * ticksPerMicrosecond);
}
示例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;
}
示例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));
}
示例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));
}
示例12: TruncSeconds
public static DateTime TruncSeconds(this DateTime dateTime)
{
return dateTime.AddTicks(-dateTime.Ticks % 600000000);
}
示例13: TruncateMilliseconds
public static DateTimeOffset TruncateMilliseconds(this DateTimeOffset dto)
{
// From http://stackoverflow.com/a/1005222/335418
return dto.AddTicks( - (dto.Ticks % TimeSpan.TicksPerSecond));
}
示例14: ToSaml2DateTimeString
public static string ToSaml2DateTimeString(this DateTime dateTime)
{
return XmlConvert.ToString(dateTime.AddTicks(-(dateTime.Ticks % TimeSpan.TicksPerSecond)),
XmlDateTimeSerializationMode.Utc);
}
示例15: SubtractTicks
public static DateTime SubtractTicks(this DateTime dateTime, long ticks)
{
return dateTime.AddTicks(-ticks);
}