本文整理汇总了C#中this.AddMinutes方法的典型用法代码示例。如果您正苦于以下问题:C# this.AddMinutes方法的具体用法?C# this.AddMinutes怎么用?C# this.AddMinutes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.AddMinutes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RoundMinutes
public static DateTime RoundMinutes(this DateTime dateTime)
{
dateTime.AddSeconds(-dateTime.Second);
dateTime.AddMilliseconds(-dateTime.Millisecond);
var remainder = dateTime.Minute % 15;
dateTime = dateTime.AddMinutes(remainder * -1);
if (remainder > 7)
{
dateTime = dateTime.AddMinutes(15);
}
return dateTime;
}
示例2: AddType
public static DateTime AddType(this DateTime instance, TimeUnits type, double increment)
{
DateTime result = instance;
switch (type)
{
case TimeUnits.Days:
result = instance.AddDays(increment);
break;
case TimeUnits.Months:
increment *= DateTime.DaysInMonth(instance.Year, instance.Month);
result = instance.AddDays((int)(Math.Floor(increment)));
break;
case TimeUnits.Weeks:
result = instance.AddDays(increment * 7);
break;
case TimeUnits.Years:
if (DateTime.IsLeapYear(instance.Year))
increment *= 366;
else
increment *= 365;
result = instance.AddDays((int)(Math.Floor(increment)));
break;
case TimeUnits.Hours:
result = instance.AddHours(increment);
break;
case TimeUnits.Minutes:
result = instance.AddMinutes(increment);
break;
}
return result;
}
示例3: Interval
public static DateTime Interval(this DateTime date, DateTimePart? intervalType, int? intervalVal)
{
if (intervalType.HasValue && intervalVal.HasValue)
{
switch (intervalType.Value)
{
case DateTimePart.Year:
return date.AddYears(intervalVal.Value);
case DateTimePart.Month:
return date.AddMonths(intervalVal.Value);
case DateTimePart.Day:
return date.AddDays((double)intervalVal.Value);
case DateTimePart.Hour:
return date.AddHours((double)intervalVal.Value);
case DateTimePart.Munite:
return date.AddMinutes((double)intervalVal.Value);
case DateTimePart.Second:
return date.AddSeconds((double)intervalVal.Value);
case DateTimePart.Week:
return date.AddDays((double)intervalVal.Value * 7);
case DateTimePart.Quarter:
return date.AddMonths(intervalVal.Value * 3);
}
}
return date;
}
示例4: NextMinute
///////////////////////////////////////////////////////////////////////
public static DateTime NextMinute(this DateTime date)
{
DateTime next = date.AddMinutes(1);
next = next.SetSecond(0);
next = next.SetMillisecond(0);
return next;
}
示例5: GeneratePartitionKeyReversed
/// <summary>
/// Generates a PartitionKey representation (in reverse order) based on the specified <see cref="DateTime"/>.
/// </summary>
/// <param name="dateTime">The DateTime.</param>
/// <returns>A string representing the Partition Key (in reverse order).</returns>
public static string GeneratePartitionKeyReversed(this DateTime dateTime)
{
dateTime = dateTime.AddMinutes(-1D);
var pk = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, 0);
return GetTicksReversed(pk);
}
示例6: Round
public static DateTime Round(this DateTime dateTime)
{
DateTime result = dateTime.AddMinutes(dateTime.Minute >= 30 ? (60 - dateTime.Minute) : (30 - dateTime.Minute));
result = result.AddSeconds(-1 * result.Second); // To reset seconds to 0
result = result.AddMilliseconds(-1 * result.Millisecond); // To reset milliseconds to 0
return result;
}
示例7: ToUTCFromClientTime
/// <summary>
/// Converts the specified client time to UTC Date Time.
/// </summary>
/// <param name="dateTime">Date time object to be converted.</param>
/// <returns>Date time in UTC time zone.</returns>
public static DateTime ToUTCFromClientTime(this DateTime dateTime)
{
var timeOffSet = HttpContext.Current.Session["__TimezoneOffset"];
if (timeOffSet != null)
{
var offset = int.Parse(timeOffSet.ToString());
dateTime = dateTime.AddMinutes(1 * offset);
}
return dateTime;
}
示例8: RoundMinutes
/// <summary>
/// Rounds the minute component to the nearest specified time. Defaults to 1 hour
/// </summary>
/// <param name="source"></param>
/// <param name="rounding"></param>
/// <returns></returns>
public static DateTime RoundMinutes(this DateTime source, MinuteRounding rounding = MinuteRounding.Hour)
{
if (rounding == MinuteRounding.QuarterHour)
throw new NotImplementedException("Coming soon");
switch (rounding)
{
case MinuteRounding.Hour:
if (source.Minute >= 30)
return source.AddHours(1).AddMinutes(-source.Minute).TrimSeconds();
return source.AddMinutes(-source.Minute).TrimSeconds();
case MinuteRounding.HalfHour:
if (source.Minute < 15)
return source.AddMinutes(-source.Minute).TrimSeconds();
if (source.Minute >= 15 && source.Minute < 45)
return source.AddMinutes(-source.Minute).AddMinutes(30).TrimSeconds();
return source.AddHours(1).AddMinutes(-source.Minute).TrimSeconds();
default:
throw new ArgumentOutOfRangeException("rounding");
}
}
示例9: LocalToUtc
public static DateTime LocalToUtc(this DateTime local, int utcOffset)
{
if (local != DateTime.MinValue && local != DateTime.MaxValue)
{
try
{
return local.AddMinutes(0 - utcOffset);
}
catch
{
}
}
return local;
}
示例10: ToClientTime
// Convert the passed datetime into client timezone.
public static string ToClientTime(this DateTime dt)
{
var timeOffSet = HttpContext.Current.Session["timezoneoffset"]; // read the value from session
if (timeOffSet != null)
{
var offset = int.Parse(timeOffSet.ToString());
dt = dt.AddMinutes(-1 * offset);
return dt.ToString();
}
// if there is no offset in session return the datetime in server timezone
return dt.ToLocalTime().ToString();
}
示例11: 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;
}
示例12: GetQuarterHourIncrementsAfter
public static IEnumerable<DateTime> GetQuarterHourIncrementsAfter(this DateTime dateTime, bool wrap = true)
{
var quarterHours = new List<DateTime>(QuarterHoursInDay);
for (int i = 1; i <= QuarterHoursInDay; i++)
{
var newDateTime = dateTime.AddMinutes(i * 15);
if (!wrap && newDateTime.Date.CompareTo(dateTime.Date) > 0)
{
break;
}
quarterHours.Add(newDateTime);
}
return quarterHours;
}
示例13: SubstractTimeStepUnit
public static DateTime SubstractTimeStepUnit(this DateTime dt, TimeStepUnit tstep)
{
switch (tstep)
{
case TimeStepUnit.Year:
return dt.AddYears(-1);
case TimeStepUnit.Month:
return dt.AddMonths(-1);
case TimeStepUnit.Day:
return dt.AddDays(-1);
case TimeStepUnit.Hour:
return dt.AddHours(-1);
case TimeStepUnit.Minute:
return dt.AddMinutes(-1);
case TimeStepUnit.Second:
return dt.AddSeconds(-1);
}
return dt;
}
示例14: MatchesCronExpression
public static bool MatchesCronExpression(this DateTime theDateTime, string cronExpression)
{
CrontabSchedule schedule;
ExceptionProvider ex;
var valueOrException = CrontabSchedule.TryParse(cronExpression,
input =>
{
schedule = input;
return true;
},
exception =>
{
ex = exception;
ex.Invoke();
return false;
});
var cronSchedule = CrontabSchedule.Parse(cronExpression);
var nextOccurrence = cronSchedule.GetNextOccurrence(theDateTime.AddMinutes(-1).AddSeconds(-1 * theDateTime.Second));
var matches = Math.Abs((theDateTime.AddSeconds(-1*theDateTime.Second) - nextOccurrence).TotalMinutes) < 1 ;
return matches;
}
示例15: NearestQuarterHour
public static DateTime NearestQuarterHour(this DateTime source)
{
var Mins = source.Minute;
int Upper = 15;
bool Found = false;
while (!Found)
{
if (Mins < (Upper - 10))
{
Mins = Upper - 15;
Found = true;
}
else if (Mins < Upper)
{
Mins = Upper;
Found = true;
}
Upper = Upper + 15;
}
return source.AddMinutes((source.Minute * -1) + Mins);
}