本文整理汇总了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);
}
示例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));
}
}
示例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;
}
示例4: RandomDate
public static DateTime RandomDate(DateTime from, DateTime to)
{
lock ( syncLock )
{
return from.AddTicks ((long) ( random.NextDouble () * ( to.Ticks - from.Ticks ) ));
}
}
示例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);
}
示例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();
}
}
示例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++;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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");
}