Class DateTimeExtensions
DateTime extensions.
Namespace: Neon.Common
Assembly: Neon.Common.dll
Syntax
public static class DateTimeExtensions
Methods
RoundDown(DateTime, TimeSpan)
Rounds a DateTime down to the nearest specified interval, like:
var date = new DateTime(2010, 02, 05, 10, 35, 25, 450); // 2010/02/05 10:35:25
var roundedDown = date.RoundDown(TimeSpan.FromMinutes(15)); // 2010/02/05 10:30:00
Declaration
public static DateTime RoundDown(this DateTime value, TimeSpan interval)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | The datetime to be rounded. |
TimeSpan | interval | The time interval to be rounded to. |
Returns
Type | Description |
---|---|
DateTime |
RoundToNearest(DateTime, TimeSpan)
Rounds a DateTime to the nearest specified interval, like:
var date = new DateTime(2010, 02, 05, 10, 35, 25, 450); // 2010/02/05 10:35:25
var roundedToNearest = date.RoundToNearest(TimeSpan.FromMinutes(15)); // 2010/02/05 10:30:00
Declaration
public static DateTime RoundToNearest(this DateTime value, TimeSpan interval)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | The datetime to be rounded. |
TimeSpan | interval | The time interval to be rounded to. |
Returns
Type | Description |
---|---|
DateTime |
RoundUp(DateTime, TimeSpan)
Rounds a DateTime up to the nearest specified interval, like:
var date = new DateTime(2010, 02, 05, 10, 35, 25, 450); // 2010/02/05 10:35:25
var roundedUp = date.RoundUp(TimeSpan.FromMinutes(15)); // 2010/02/05 10:45:00
Declaration
public static DateTime RoundUp(this DateTime value, TimeSpan interval)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | The datetime to be rounded. |
TimeSpan | interval | The time interval to be rounded to. |
Returns
Type | Description |
---|---|
DateTime | The rounded date. |
ToUnixEpochMilliseconds(DateTime)
Converts the DateTime into the number of milliseconds since the Unix Epoc (midnight 1-1-1070 UTC).
Declaration
public static long ToUnixEpochMilliseconds(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | The time being converted. |
Returns
Type | Description |
---|---|
long | The Unix time in milliseconds. |
ToUnixEpochNanoseconds(DateTime)
Converts the DateTime into the number of neonseconds since the Unix Epoc (midnight 1-1-1070 UTC).
Declaration
public static long ToUnixEpochNanoseconds(this DateTime value)
Parameters
Type | Name | Description |
---|---|---|
DateTime | value | The time being converted. |
Returns
Type | Description |
---|---|
long | The Unix time in naonseconds. |