本文整理汇总了C#中System.Globalization.Calendar.GetSecond方法的典型用法代码示例。如果您正苦于以下问题:C# Calendar.GetSecond方法的具体用法?C# Calendar.GetSecond怎么用?C# Calendar.GetSecond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.Calendar
的用法示例。
在下文中一共展示了Calendar.GetSecond方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NextValid
/// <summary>
/// Get's the next valid second after the current .
/// </summary>
/// <param name="dateTime">The date time (fractions of a second are removed).</param>
/// <param name="month">The month.</param>
/// <param name="week">The week.</param>
/// <param name="day">The day.</param>
/// <param name="weekDay">The week day.</param>
/// <param name="hour">The hour.</param>
/// <param name="minute">The minute.</param>
/// <param name="second">The second.</param>
/// <param name="calendar">The calendar.</param>
/// <param name="calendarWeekRule">The calendar week rule.</param>
/// <param name="firstDayOfWeek">The first day of week.</param>
/// <param name="inclusive">if set to <c>true</c> can return the time specified, otherwise, starts at the next second..</param>
/// <returns>
/// The next valid date (or <see cref="DateTime.MaxValue"/> if none).
/// </returns>
public static DateTime NextValid(
this DateTime dateTime,
Month month = Month.Every,
Week week = Week.Every,
Day day = Day.Every,
WeekDay weekDay = WeekDay.Every,
Hour hour = Hour.Zeroth,
Minute minute = Minute.Zeroth,
Second second = Second.Zeroth,
Calendar calendar = null,
CalendarWeekRule calendarWeekRule = CalendarWeekRule.FirstFourDayWeek,
DayOfWeek firstDayOfWeek = DayOfWeek.Sunday,
bool inclusive = false)
{
// Never case, if any are set to never, we'll never get a valid date.
if ((month == Month.Never) || (week == Week.Never) ||
(day == Day.Never) || (weekDay == WeekDay.Never) || (hour == Hour.Never) ||
(minute == Minute.Never) ||
(second == Second.Never))
return DateTime.MaxValue;
if (calendar == null)
calendar = CultureInfo.CurrentCulture.Calendar;
// Set the time to this second (or the next one if not inclusive), remove fractions of a second.
dateTime = new DateTime(
dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second);
if (!inclusive)
dateTime = calendar.AddSeconds(dateTime, 1);
// Every second case.
if ((month == Month.Every) && (day == Day.Every) && (weekDay == WeekDay.Every) && (hour == Hour.Every) &&
(minute == Minute.Every) && (second == Second.Every) &&
(week == Week.Every))
return calendar.AddSeconds(dateTime, 1);
// Get days and months.
IEnumerable<int> days = day.Days().OrderBy(dy => dy);
IEnumerable<int> months = month.Months();
// Remove months where the first day isn't in the month.
int firstDay = days.First();
if (firstDay > 28)
{
// 2000 is a leap year, so February has 29 days.
months = months.Where(mn => calendar.GetDaysInMonth(2000, mn) >= firstDay);
if (months.Count() < 1)
return DateTime.MaxValue;
}
// Get remaining date components.
int y = calendar.GetYear(dateTime);
int m = calendar.GetMonth(dateTime);
int d = calendar.GetDayOfMonth(dateTime);
int h = calendar.GetHour(dateTime);
int n = calendar.GetMinute(dateTime);
int s = calendar.GetSecond(dateTime);
IEnumerable<int> weeks = week.Weeks();
IEnumerable<DayOfWeek> weekDays = weekDay.WeekDays();
IEnumerable<int> hours = hour.Hours().OrderBy(i => i);
IEnumerable<int> minutes = minute.Minutes().OrderBy(i => i);
IEnumerable<int> seconds = second.Seconds();
do
{
foreach (int currentMonth in months)
{
if (currentMonth < m)
continue;
if (currentMonth > m)
{
d = 1;
h = n = s = 0;
}
m = currentMonth;
foreach (int currentDay in days)
{
if (currentDay < d)
continue;
if (currentDay > d)
//.........这里部分代码省略.........