Class DateTimeExtensions
Contains useful extensions of the DateTime structure.
Inherited Members
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.dll
Syntax
public static class DateTimeExtensions
Fields
| Edit this page View SourceCenturyEpoch
Gets a DateTime that represents the beginning of the 20th century time.
Declaration
public static readonly DateTime CenturyEpoch
Field Value
Type | Description |
---|---|
DateTime |
Remarks
The Century Epoch is defined as the starting point of time for many 32-bit devices that do not follow the Unix standard, and is set as the first of January of the year 1900. The standard was defined by means of GMT time, in its absence UTC is used as a sufficiently close substitute.
UnixEpoch
Gets a DateTime that represents the beginning of the Unix time.
Declaration
public static readonly DateTime UnixEpoch
Field Value
Type | Description |
---|---|
DateTime |
Y2KEpoch
Gets a DateTime that represents the beginning of the 21st century time.
Declaration
public static readonly DateTime Y2KEpoch
Field Value
Type | Description |
---|---|
DateTime |
Remarks
The Y2K Epoch is defined as the starting point of time for 32-bit devices that do not follow the Unix standard, and is set as the first of January of the year 2000.
Methods
| Edit this page View SourceEpoch(in int)
Creates a DateTime that represents the beginning of time for a specific year.
Declaration
public static DateTime Epoch(in int year)
Parameters
Type | Name | Description |
---|---|---|
int | year |
Returns
Type | Description |
---|---|
DateTime |
FromTimestamp(in long, in DateTime)
Gets a DateTime from a Timestamp.
Declaration
public static DateTime FromTimestamp(in long seconds, in DateTime epoch)
Parameters
Type | Name | Description |
---|---|---|
long | seconds | Number of seconds since the specified Epoch. |
DateTime | epoch | Initial epoch to use. |
Returns
Type | Description |
---|---|
DateTime | A DateTime constructed from the Timestamp. |
FromTimestampMs(in long, in DateTime)
Gets a DateTime from a Timestamp in milliseconds.
Declaration
public static DateTime FromTimestampMs(in long milliseconds, in DateTime epoch)
Parameters
Type | Name | Description |
---|---|---|
long | milliseconds | Number of seconds since the specified Epoch. |
DateTime | epoch | Initial epoch to use. |
Returns
Type | Description |
---|---|
DateTime | A DateTime constructed from the Timestamp. |
FromUnixTimestamp(in long)
Gets a DateTime from a Unix Timestamp.
Declaration
public static DateTime FromUnixTimestamp(this in long seconds)
Parameters
Type | Name | Description |
---|---|---|
long | seconds | Number of seconds since the Unix Epoch. |
Returns
Type | Description |
---|---|
DateTime | A DateTime constructed from the Unix Timestamp. |
FromUnixTimestampMs(in long)
Gets a DateTime from a Unix Timestamp.
Declaration
public static DateTime FromUnixTimestampMs(this in long milliseconds)
Parameters
Type | Name | Description |
---|---|---|
long | milliseconds | Number of milliseconds since the Unix Epoch. |
Returns
Type | Description |
---|---|
DateTime | A DateTime constructed from the Unix Timestamp. |
MonthName(in int)
Gets the name of the specified month.
Declaration
public static string MonthName(in int month)
Parameters
Type | Name | Description |
---|---|---|
int | month | Month number from which to get the name. |
Returns
Type | Description |
---|---|
string | The name of the month specified. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | This is thrown if |
MonthName(in int, in CultureInfo)
Gets the name of the specified month.
Declaration
public static string MonthName(in int month, in CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
int | month | Month number from which to get the name. |
CultureInfo | culture | Culture to use to get the name. |
Returns
Type | Description |
---|---|
string | The name of the month specified. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | This is thrown if |
ToTimestamp(in DateTime, in DateTime)
Converts a DateTime to a 64-bit Timestamp.
Declaration
public static long ToTimestamp(this in DateTime dateTime, in DateTime epoch)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | Time value to convert. |
DateTime | epoch | Initial epoch to use. |
Returns
Type | Description |
---|---|
long | A long that represents the value of the Timestamp of the specified DateTime. |
ToTimestampMs(in DateTime, in DateTime)
Converts a DateTime to a 64-bit Timestamp.
Declaration
public static long ToTimestampMs(this in DateTime dateTime, in DateTime epoch)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | Time value to convert. |
DateTime | epoch | Initial epoch to use. |
Returns
Type | Description |
---|---|
long | A long that represents the value of the Timestamp of the specified DateTime. |
ToUnixTimestamp(in DateTime)
Converts a DateTime to a 64-bit Unix Timestamp.
Declaration
public static long ToUnixTimestamp(this in DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | Time value to convert. |
Returns
Type | Description |
---|---|
long | A long that represents the value of the Unix Timestamp of the specified DateTime. |
ToUnixTimestampMs(in DateTime)
Converts a DateTime to a 64-bit Unix Timestamp in milliseconds.
Declaration
public static long ToUnixTimestampMs(this in DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | Time value to convert. |
Returns
Type | Description |
---|---|
long | A long that represents the value of the Unix Timestamp in milliseconds of the specified DateTime. |