Class DateTimeOffsetExtensions
Extensions that provide utility methods for the DateTimeOffset struct.
public static class DateTimeOffsetExtensions
- Inheritance
-
DateTimeOffsetExtensions
- Inherited Members
Methods
AsTimeZoneSilently(DateTimeOffset, string)
Shifts the given DateTimeOffset to the specified time zone (e.g. keep date and time, change only the time zone). Returns null if the time zone ID is invalid or not found.
public static DateTimeOffset? AsTimeZoneSilently(this DateTimeOffset dateTime, string tzId)
Parameters
dateTimeDateTimeOffsettzIdstring
Returns
IsOnDayOfWeek(DateTimeOffset, IEnumerable<DayOfWeek>)
Checks if the day of week component of the given DateTimeOffset falls on any of the specified days of week.
public static bool IsOnDayOfWeek(this DateTimeOffset dateTime, IEnumerable<DayOfWeek> dows)
Parameters
dateTimeDateTimeOffsetdowsIEnumerable<DayOfWeek>
Returns
IsOnDayOfWeek(DateTimeOffset, IEnumerable<string>)
Checks if the day of week component of the given DateTimeOffset falls on any of the specified days of week (case-insensitive, supports both full and abbreviated day of week names).
public static bool IsOnDayOfWeek(this DateTimeOffset dateTime, IEnumerable<string> dows)
Parameters
dateTimeDateTimeOffsetdowsIEnumerable<string>
Returns
IsOnDayOfWeek(DateTimeOffset, params DayOfWeek[])
Checks if the day of week component of the given DateTimeOffset falls on any of the specified days of week.
public static bool IsOnDayOfWeek(this DateTimeOffset dateTime, params DayOfWeek[] dows)
Parameters
dateTimeDateTimeOffsetdowsDayOfWeek[]
Returns
IsOnDayOfWeek(DateTimeOffset, params string[])
Checks if the day of week component of the given DateTimeOffset falls on any of the specified days of week (case-insensitive, supports both full and abbreviated day of week names).
public static bool IsOnDayOfWeek(this DateTimeOffset dateTime, params string[] dows)
Parameters
dateTimeDateTimeOffsetdowsstring[]
Returns
IsWithinTimeWindow(DateTimeOffset, TimeOnly, TimeOnly)
Checks if the time component of the given DateTimeOffset falls within the specified time window (e.g. start <= dateTime < end).
public static bool IsWithinTimeWindow(this DateTimeOffset dateTime, TimeOnly startInclusive, TimeOnly endExclusive)
Parameters
dateTimeDateTimeOffsetstartInclusiveTimeOnlyendExclusiveTimeOnly
Returns
Remarks
The time window can span across midnight. For example, a time window from 22:00 to 02:00 will include times from 22:00 to 23:59 and from 00:00 to 02:00.
NextWeekDay(DateTimeOffset)
Returns a new DateTimeOffset representing the next weekday (Monday to Friday) of the given DateTimeOffset.
public static DateTimeOffset NextWeekDay(this DateTimeOffset dateTime)
Parameters
dateTimeDateTimeOffset
Returns
PrevWeekDay(DateTimeOffset)
Returns a new DateTimeOffset representing the previous weekday (Monday to Friday) of the given DateTimeOffset.
public static DateTimeOffset PrevWeekDay(this DateTimeOffset dateTime)
Parameters
dateTimeDateTimeOffset
Returns
StartOfDay(DateTimeOffset)
Returns a new DateTimeOffset with the time component set to 00:00:00
public static DateTimeOffset StartOfDay(this DateTimeOffset dateTime)
Parameters
dateTimeDateTimeOffset
Returns
ToTimeZoneSilently(DateTimeOffset, string)
Converts the given DateTimeOffset to the specified time zone. Returns null if the time zone ID is invalid or not found.
public static DateTimeOffset? ToTimeZoneSilently(this DateTimeOffset dateTime, string tzId)
Parameters
dateTimeDateTimeOffsettzIdstring