Class DateTimeExtensions
Extension methods for
Inheritance
Namespace: X10D.Time
Assembly: X10D.dll
Syntax
public static class DateTimeExtensions : object
Methods
| Improve this Doc View SourceAge(DateTime)
Returns the rounded-down integer number of years since a given date as of today.
Declaration
public static int Age(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value |
Returns
Type | Description |
---|---|
System.Int32 | The rounded-down integer number of years since |
Age(DateTime, DateTime)
Returns the rounded-down integer number of years since a given date as of another specified date.
Declaration
public static int Age(this DateTime value, DateTime referenceDate)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | |
DateTime | referenceDate |
Returns
Type | Description |
---|---|
System.Int32 | The rounded-down integer number of years since |
First(DateTime, DayOfWeek)
Gets a date representing the first occurence of a specified day of the week in the current month.
Declaration
public static DateTime First(this DateTime value, DayOfWeek dayOfWeek)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | |
DayOfWeek | dayOfWeek | The day of the week. |
Returns
Type | Description |
---|---|
DateTime | A |
FirstDayOfMonth(DateTime)
Gets a date representing the first day of the current month.
Declaration
public static DateTime FirstDayOfMonth(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value |
Returns
Type | Description |
---|---|
DateTime | A |
GetIso8601WeekOfYear(DateTime)
Gets the ISO-8601 week number of the year for the current date.
Declaration
public static int GetIso8601WeekOfYear(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | The date whose week number to return. |
Returns
Type | Description |
---|---|
System.Int32 | The ISO-8601 week number of the year. |
Remarks
This implementation is directly inspired from a blog post . about this subject.
IsLeapYear(DateTime)
Returns a value indicating whether the year represented by the current
Declaration
public static bool IsLeapYear(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | The date whose year to check. |
Returns
Type | Description |
---|---|
System.Boolean | true if the year represented by |
Last(DateTime, DayOfWeek)
Gets a date representing the final occurence of a specified day of the week in the current month.
Declaration
public static DateTime Last(this DateTime value, DayOfWeek dayOfWeek)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | |
DayOfWeek | dayOfWeek | The day of the week. |
Returns
Type | Description |
---|---|
DateTime | A |
LastDayOfMonth(DateTime)
Gets a date representing the last day of the current month.
Declaration
public static DateTime LastDayOfMonth(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value |
Returns
Type | Description |
---|---|
DateTime | A |
Next(DateTime, DayOfWeek)
Gets a date representing the next occurence of a specified day of the week in the current month.
Declaration
public static DateTime Next(this DateTime value, DayOfWeek dayOfWeek)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | |
DayOfWeek | dayOfWeek | The day of the week. |
Returns
Type | Description |
---|---|
DateTime | A |
ToUnixTimeMilliseconds(DateTime)
Returns the number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.
Declaration
public static long ToUnixTimeMilliseconds(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | The current date. |
Returns
Type | Description |
---|---|
System.Int64 | The number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z. |
ToUnixTimeSeconds(DateTime)
Returns the number of seconds that have elapsed since 1970-01-01T00:00:00.000Z.
Declaration
public static long ToUnixTimeSeconds(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | The current date. |
Returns
Type | Description |
---|---|
System.Int64 | The number of seconds that have elapsed since 1970-01-01T00:00:00.000Z. |