123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Globalization;
- namespace EasyDevCore.Common
- {
- /// <summary>
- /// DateTime extension helper
- /// </summary>
- public static class DateTimeExtensions
- {
- /// <summary>
- /// Parses by format.
- /// </summary>
- /// <param name="input">The input.</param>
- /// <param name="format">The format.</param>
- /// <returns></returns>
- public static DateTime ParseByFormat(this DateTime input, string format)
- {
- return DateTime.ParseExact(input.ToString(format), format, System.Globalization.CultureInfo.InvariantCulture);
- }
- /// <summary>
- /// Gets the week of month.
- /// </summary>
- /// <param name="time">The time.</param>
- /// <returns></returns>
- public static int GetWeekOfMonth(this DateTime time)
- {
- DateTime first = new DateTime(time.Year, time.Month, 1);
- return time.GetWeekOfYear() - first.GetWeekOfYear() + 1;
- }
- /// <summary>
- /// Gets the week of year.
- /// </summary>
- /// <param name="time">The time.</param>
- /// <returns></returns>
- public static int GetWeekOfYear(this DateTime time)
- {
- return new GregorianCalendar().GetWeekOfYear(time, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
- }
- }
- }
|