Class DateTimeExtensions
Provides extension methods for DateTime.
Namespace: Sartorius.SAF.Extensions
Assembly: Sartorius.SAF.dll
Syntax
public static class DateTimeExtensions
Methods
View SourceRoundToPrecision(DateTime, int)
Rounds to the given count of decimals. e.g. 2 will round to 1/100th second.
Declaration
public static DateTime RoundToPrecision(this DateTime value, int decimals)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | value | The value. |
| int | decimals | The decimals. |
Returns
| Type | Description |
|---|---|
| DateTime |
Examples
The following example rounds a datetime to 1/100th (2 decimals) of a second.
View Source
RoundToTicks(DateTime, long)
Rounds to the specified ticks.
Declaration
public static DateTime RoundToTicks(this DateTime value, long precision)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | value | The value. |
| long | precision | The tick precision. |
Returns
| Type | Description |
|---|---|
| DateTime |
Examples
The following example rounds a datetime to full days by using TicksPerDay.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | precision;precisions must be greater than 0. |