DateTimeHelper Class
Namespace: PTS
Assembly: PTSframework.dll
Provides a set of static methods for DateTime
type.
Syntax
public static class DateTimeHelper
Inheritance
Methods
AddDifference(DateTime, DateTime)
Adds time difference of the two time values to give time.
Declaration
public static DateTime AddDifference(this DateTime time, DateTime otherTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | time | Time to add the difference to. |
System.DateTime | otherTime | Time to get the difference for. |
Returns
Type | Description |
---|---|
System.DateTime |
|
AddTime(DateTime, Time)
Adds time to instant in time represented as DateTime
.
Declaration
public static DateTime AddTime(this DateTime date, Time time)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | date | Date to add time to. |
Time | time | Time that will be added to date. |
Returns
Type | Description |
---|---|
System.DateTime |
|
AddTime(Nullable<DateTime>, Nullable<Time>)
Adds time to point in time represented as nullable DateTime
.
Declaration
public static DateTime AddTime(this DateTime? date, Time? time)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | date | Date to add time to. |
System.Nullable<Time> | time | Time that will be added to date. |
Returns
Type | Description |
---|---|
System.DateTime |
|
AddWeeks(DateTime, Int32)
Gets a new DateTime with specified number of weeks added to given instant in time.
Declaration
public static DateTime AddWeeks(this DateTime time, int weeks)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | time | An instant of time to add the weeks to. |
System.Int32 | weeks | A number of whole weeks. The value parameter can be negative or positive. |
Returns
Type | Description |
---|---|
System.DateTime |
DaysSinceJesus(DateTime)
Gets number of whole days since zero year.
Declaration
public static int DaysSinceJesus(this DateTime date)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | date | An instant of time to be represented as number of days since zero year. |
Returns
Type | Description |
---|---|
System.Int32 | Number of days since zero year. |
EndOfDay(DateTime)
Gets a new DateTime representing instant at the last second of the day component in given DateTime.
Declaration
public static DateTime EndOfDay(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the last second of the day for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant at the last second of given day. |
EndOfDay(Nullable<DateTime>)
Gets a new DateTime representing instant at the last second of the day component in given nullable DateTime.
Declaration
public static DateTime? EndOfDay(this DateTime? dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | Instant at the last second of given day if the original value was not |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | Instant at the last second of given day. |
EndOfHour(DateTime)
Gets a new DateTime representing instant at the last second of hour component in given DateTime.
Declaration
public static DateTime EndOfHour(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the last second of an hour for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant at the last second of given hour. |
EndOfMonth(DateTime)
Gets a new DateTime representing instant at the last second of month component in given DateTime.
Declaration
public static DateTime EndOfMonth(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the last second of a month for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant at the last second of given month. |
EndOfWeek(DateTime, Boolean)
Gets a new DateTime representing instant at the last second of a week represented in given DateTime.
Declaration
public static DateTime EndOfWeek(this DateTime dateTime, bool weekStartsOnMonday = false)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the last second of a week for. |
System.Boolean | weekStartsOnMonday | Indicates whether week starts on Monday. If |
Returns
Type | Description |
---|---|
System.DateTime | Instant at the last second of given week. |
EndOfWeek(Nullable<DateTime>, Boolean)
Gets a new DateTime representing instant at the last second of a week represented in given nullable DateTime.
Declaration
public static DateTime? EndOfWeek(this DateTime? dateTime, bool weekStartsOnMonday = false)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | An instant of time to get the last second of a week for. |
System.Boolean | weekStartsOnMonday | Indicates whether week starts on Monday. If |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | Instant at the last second of given week. |
EndOfYear(DateTime)
Gets a new DateTime representing instant at the last second of year component in given DateTime.
Declaration
public static DateTime EndOfYear(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the last second of a year for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant at the last second of given year. |
FromUnixTime(Int64, Boolean)
Converts seconds or milliseconds since epoch to date and time represented as DateTime
value.
Declaration
public static DateTime FromUnixTime(long timestamp, bool milliseconds = false)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | timestamp | A unix timestamp to convert to |
System.Boolean | milliseconds | If set to |
Returns
Type | Description |
---|---|
System.DateTime | An instant represented as |
IsBetween(DateTime, DateTime, DateTime, Boolean)
Checks whether the value of given DateTime
is between start and end values.
Declaration
public static bool IsBetween(this DateTime dateTime, DateTime start, DateTime end, bool inclusiveStart = true)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to check the range for. |
System.DateTime | start | An instant in time the value must be greater than. |
System.DateTime | end | An instant in time the value must be lesser than. |
System.Boolean | inclusiveStart | If |
Returns
Type | Description |
---|---|
System.Boolean | If the |
IsBetweenHours(DateTime, Int32, Int32, Boolean)
Checks whether the hour component of DateTime
value is between start and end hours.
Declaration
public static bool IsBetweenHours(this DateTime dateTime, int startHour, int endHour, bool inclusiveStart = true)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to check the hour range for. |
System.Int32 | startHour | Starting hour the DateTime hour component must superceed. |
System.Int32 | endHour | Ending hour the DateTime hour component must not exceed. |
System.Boolean | inclusiveStart | If |
Returns
Type | Description |
---|---|
System.Boolean | If |
IsEndOfDay(DateTime)
Checks whether the value represents the end of day on given date.
Declaration
public static bool IsEndOfDay(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to check if it represants the end of day. |
Returns
Type | Description |
---|---|
System.Boolean | If the value represents the last second of given day then |
IsInThePast(DateTime)
Checks whether given DateTime
value is in the past.
Declaration
public static bool IsInThePast(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to determine whether it is in the past or not. |
Returns
Type | Description |
---|---|
System.Boolean | If the value is in the past then |
Remarks
The method performs simple evaluation dateTime < SystemTime.Now
IsSameDay(DateTime, DateTime)
Checks whether two DateTime
values represent the same day.
Declaration
public static bool IsSameDay(this DateTime dateTime, DateTime otherDate)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | Value to determine the outcome for. |
System.DateTime | otherDate | Other value used for comparison. |
Returns
Type | Description |
---|---|
System.Boolean | If both values represent the same day then |
Remarks
The method checks for absolute day match inclusive of year and month components.
IsSameHour(DateTime, DateTime)
Checks whether two DateTime
values represent the same hour.
Declaration
public static bool IsSameHour(this DateTime dateTime, DateTime otherDate)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | Value to determine the outcome for. |
System.DateTime | otherDate | Other value used for comparison. |
Returns
Type | Description |
---|---|
System.Boolean | If both values represent the same hour then |
Remarks
The method checks for absolute hour match inclusive of year, month and day components.
IsSameMonth(DateTime, DateTime)
Checks whether two DateTime
values represent the same month.
Declaration
public static bool IsSameMonth(this DateTime dateTime, DateTime otherDate)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | Value to determine the outcome for. |
System.DateTime | otherDate | Other value used for comparison. |
Returns
Type | Description |
---|---|
System.Boolean | If both values represent the same month then |
Remarks
The method checks for absolute month match inclusive of year component.
IsSameWeek(DateTime, DateTime)
Checks whether two DateTime
values represent the same week.
Declaration
public static bool IsSameWeek(this DateTime dateTime, DateTime otherDate)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | Value to determine the outcome for. |
System.DateTime | otherDate | Other value used for comparison. |
Returns
Type | Description |
---|---|
System.Boolean | If both values represent the same week then |
Remarks
The method checks for absolute week number match inclusive of the year component.
IsStartOfDay(DateTime)
Checks whether an instant in time represents the start of a day.
Declaration
public static bool IsStartOfDay(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to check if it represants the start of a day. |
Returns
Type | Description |
---|---|
System.Boolean | If value represents the first second of given day then |
IsZeroDate(DateTime)
Checks whether an instant in time represents the zero date.
Declaration
public static bool IsZeroDate(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to check if it represants zero date. |
Returns
Type | Description |
---|---|
System.Boolean | If value represents the zero date then |
IsZeroDateOrNull(Nullable<DateTime>)
Checks whether a nullable instant in time is either null
or represents the zero date.
Declaration
public static bool IsZeroDateOrNull(this DateTime? dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | abstractnullable instant of time to check if it is |
Returns
Type | Description |
---|---|
System.Boolean | If value is |
RoundDown(DateTime, TimeSpan)
Rounds the instant of time to the nearest lesser unit of time represented as TimeSpan
.
Declaration
public static DateTime RoundDown(this DateTime dateTime, TimeSpan roundTo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The instant of time to round. |
System.TimeSpan | roundTo | Unit of time for rounding. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time rounded down to nearest lower unit of time. |
RoundToNearest(DateTime, TimeSpan)
Rounds the instant of time to the nearest lesser or greater unit of time represented as TimeSpan
.
Declaration
public static DateTime RoundToNearest(this DateTime dateTime, TimeSpan roundTo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The instant of time to round. |
System.TimeSpan | roundTo | Unit of time for rounding. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time rounded to nearest lesser or greater unit of time. |
RoundUp(DateTime, TimeSpan)
Rounds up.
Declaration
public static DateTime RoundUp(this DateTime dateTime, TimeSpan roundTo)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The date time. |
System.TimeSpan | roundTo | The round to. Fx. TimeSpan.FromMinutes(15). |
Returns
Type | Description |
---|---|
System.DateTime |
SetTime(DateTime, Time)
Sets the hour, minute and second components from Time value.
Declaration
public static DateTime SetTime(this DateTime dateTime, Time time)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | Value to set the hour, minute and second for. |
Time | time | Time value to get the time components from. |
Returns
Type | Description |
---|---|
System.DateTime | A new instant in time with hour, minute and second components assigned from Time value. |
SetTime(DateTime, DateTime)
Sets the hour, minute and second components from other DateTime
value.
Declaration
public static DateTime SetTime(this DateTime dateTime, DateTime otherDateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | Value to set the hour, minute and second for. |
System.DateTime | otherDateTime | Other value to get the time components from. |
Returns
Type | Description |
---|---|
System.DateTime | A new instant in time with hour, minute and second components assigned from other value. |
SetTime(Nullable<DateTime>, Nullable<DateTime>)
Sets the hour, minute and second components from other nullable DateTime
value.
Declaration
public static DateTime? SetTime(this DateTime? dateTime, DateTime? otherDateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | Nullable value to set the hour, minute and second for. |
System.Nullable<System.DateTime> | otherDateTime | Other nullable value to get the time components from. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | A new instant in time with hour, minute and second components assigned from other value. |
StartOfDay(DateTime)
Gets an instant in time for the first millisecond of a day.
Declaration
public static DateTime StartOfDay(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the first millisecond of a day for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant in time for the first millisecond of a day. |
StartOfDay(Nullable<DateTime>)
Gets an instant in time for the first millisecond of a day.
Declaration
public static DateTime? StartOfDay(this DateTime? dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | A nullable instant of time to get the first millisecond of a day for. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | If given value is not |
StartOfHour(DateTime)
Gets an instant in time for the first millisecond of an hour.
Declaration
public static DateTime StartOfHour(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the first millisecond of an hour for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant in time for the first millisecond of an hour. |
StartOfHour(Nullable<DateTime>)
Gets an instant in time for the first millisecond of an hour.
Declaration
public static DateTime? StartOfHour(this DateTime? dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | A nullable instant of time to get the first millisecond of an hour for. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | If given value is not |
StartOfMinute(DateTime)
Gets an instant in time for the first millisecond of a minute.
Declaration
public static DateTime StartOfMinute(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the first millisecond of a minute for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant in time for the first millisecond of a minute. |
StartOfMinute(Nullable<DateTime>)
Gets an instant in time for the first millisecond of a minute.
Declaration
public static DateTime? StartOfMinute(this DateTime? dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | A nullable instant of time to get the first millisecond of a minute for. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | If given value is not |
StartOfMonth(DateTime)
Gets an instant in time for the first millisecond of a month.
Declaration
public static DateTime StartOfMonth(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the first millisecond of a month for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant in time for the first millisecond of a month. |
StartOfMonth(Nullable<DateTime>)
Gets an instant in time for the first millisecond of a month.
Declaration
public static DateTime? StartOfMonth(this DateTime? dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | A nullable instant of time to get the first millisecond of a month for. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | If given value is not |
StartOfSecond(DateTime)
Gets an instant in time for the first millisecond of a second.
Declaration
public static DateTime StartOfSecond(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the first millisecond of a second for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant in time for the first millisecond of a second. |
StartOfSecond(Nullable<DateTime>)
Gets an instant in time for the first millisecond of a second.
Declaration
public static DateTime? StartOfSecond(this DateTime? dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | A nullable instant of time to get the first millisecond of a second for. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | If given value is not |
StartOfWeek(DateTime, Boolean)
Gets an instant in time for the first millisecond of a week.
Declaration
public static DateTime StartOfWeek(this DateTime dateTime, bool weekStartsOnMonday = false)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the first millisecond of a week for. |
System.Boolean | weekStartsOnMonday |
Returns
Type | Description |
---|---|
System.DateTime | Instant in time for the first millisecond of a week. |
StartOfWeek(Nullable<DateTime>, Boolean)
Gets an instant in time for the first millisecond of a week.
Declaration
public static DateTime? StartOfWeek(this DateTime? dateTime, bool weekStartsOnMonday = false)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | A nullable instant of time to get the first millisecond of a week for. |
System.Boolean | weekStartsOnMonday |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | If given value is not |
StartOfYear(DateTime)
Gets an instant in time for the first millisecond of a year.
Declaration
public static DateTime StartOfYear(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the first millisecond of a year for. |
Returns
Type | Description |
---|---|
System.DateTime | Instant in time for the first millisecond of a year. |
StartOfYear(Nullable<DateTime>)
Gets an instant in time for the first millisecond of a year.
Declaration
public static DateTime? StartOfYear(this DateTime? dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | A nullable instant of time to get the first millisecond of a year for. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | If given value is not |
SubtractDays(DateTime, Int32)
Returns a new DateTime
that subtracts the specified number of days from the value of this instance.
Declaration
public static DateTime SubtractDays(this DateTime dateTime, int days)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time value to subtract from. |
System.Int32 | days | Number of days to subtract. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time whose value is the remainder of the days subtracted from a date and time. |
SubtractHours(DateTime, Int32)
Returns a new DateTime
that subtracts the specified number of hours from the value of this instance.
Declaration
public static DateTime SubtractHours(this DateTime dateTime, int hours)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time value to subtract from. |
System.Int32 | hours | Number of hours to subtract. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time whose value is the remainder of the hours subtracted from a date and time. |
SubtractMinutes(DateTime, Int32)
Returns a new DateTime
that subtracts the specified number of minutes from the value of this instance.
Declaration
public static DateTime SubtractMinutes(this DateTime dateTime, int minutes)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time value to subtract from. |
System.Int32 | minutes | Number of minutes to subtract. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time whose value is the remainder of the minutes subtracted from a date and time. |
SubtractMonths(DateTime, Int32)
Returns a new DateTime
that subtracts the specified number of months from the value of this instance.
Declaration
public static DateTime SubtractMonths(this DateTime dateTime, int months)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time value to subtract from. |
System.Int32 | months | Number of months to subtract. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time whose value is the remainder of the months subtracted from a date and time. |
SubtractSeconds(DateTime, Int32)
Returns a new DateTime
that subtracts the specified number of seconds from the value of this instance.
Declaration
public static DateTime SubtractSeconds(this DateTime dateTime, int seconds)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time value to subtract from. |
System.Int32 | seconds | Number of seconds to subtract. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time whose value is the remainder of the seconds subtracted from a date and time. |
SubtractTime(DateTime, Time)
Returns a new DateTime
that subtracts the specified Time from the value of this instance.
Declaration
public static DateTime SubtractTime(this DateTime dateTime, Time time)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time value to subtract from. |
Time | time | A time value to subtract. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time whose value is the remainder of the Time subtracted from a date and time. |
SubtractTime(Nullable<DateTime>, Time)
Returns a new nullable DateTime
that subtracts the specified Time from the value of this instance.
Declaration
public static DateTime? SubtractTime(this DateTime? dateTime, Time time)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | A nullable date and time value to subtract from. |
Time | time | A time value to subtract. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | An instant in time whose value is the remainder of the Time subtracted from a date and time if given value was not |
SubtractYears(DateTime, Int32)
Returns a new DateTime
that subtracts the specified number of years from the value of this instance.
Declaration
public static DateTime SubtractYears(this DateTime dateTime, int years)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time value to subtract from. |
System.Int32 | years | Number of years to subtract. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time whose value is the remainder of the years subtracted from a date and time. |
ToHourString(DateTime)
Gets the hour component of a DateTime
value represented as fixed width string.
Declaration
public static string ToHourString(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time value to get the hour component as string for. |
Returns
Type | Description |
---|---|
System.String | A fixed width string representing an hour component of give date and time. |
ToIsoDateTime(DateTime)
Gets the date and time represented as iso date and time string.
Declaration
public static string ToIsoDateTime(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time to get the iso string for. |
Returns
Type | Description |
---|---|
System.String | A string representing the full date and time value in iso format. |
Remarks
The iso format is suitable for API implementations.
ToMinuteString(DateTime)
Gets the minute component of a DateTime
value represented as fixed width string.
Declaration
public static string ToMinuteString(this DateTime date)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | date |
Returns
Type | Description |
---|---|
System.String | A fixed width string representing an minute component of give date and time. |
ToNextInterval(DateTime, Int32)
Gets an instant in time of the next midnight based interval in milliseconds.
Declaration
public static DateTime ToNextInterval(this DateTime dateTime, int ms)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | An instant of time to get the next interval instant of time for. |
System.Int32 | ms | Time interval size in milliseconds. |
Returns
Type | Description |
---|---|
System.DateTime | An instant in time for the start of the next time interval. |
ToSecondString(DateTime)
Gets the second component of a DateTime
value represented as fixed width string.
Declaration
public static string ToSecondString(this DateTime date)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | date |
Returns
Type | Description |
---|---|
System.String | A fixed width string representing an second component of give date and time. |
ToTime(DateTime)
Gets an hour, minute and second components as Time value.
Declaration
public static Time ToTime(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time to get the Time from. |
Returns
Type | Description |
---|---|
Time | A new Time value with the components set from given date and time. |
ToTime(Nullable<DateTime>)
Gets an hour, minute and second components as Time value.
Declaration
public static Time? ToTime(this DateTime? dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | dateTime | A nullable date and time to get the Time from. |
Returns
Type | Description |
---|---|
System.Nullable<Time> | A new Time value with the components set from date and time if given value was not |
ToUnixTime(DateTime, Boolean)
Gets the date and time represented as number of seconds or milliseconds since epoch.
Declaration
public static ulong ToUnixTime(this DateTime dateTime, bool asMilliseconds = false)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | A date and time value to convert to unix timestamp. |
System.Boolean | asMilliseconds | If set to |
Returns
Type | Description |
---|---|
System.UInt64 | Number of seconds or milliseconds since epoch. |
ToWeekNumber(DateTime)
Gets week number for given instant in time.
Declaration
public static int ToWeekNumber(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The instant in time to get the week number for. |
Returns
Type | Description |
---|---|
System.Int32 | Week number for given instant in time. |