Class DateTimeConverter
Helper class to handler date time from and to local and utc.
Inheritance
Inherited Members
Namespace: EPiServer.Data
Assembly: EPiServer.Data.dll
Version: 11.20.7Syntax
public abstract class DateTimeConverter
Constructors
DateTimeConverter()
Declaration
protected DateTimeConverter()
Properties
MaxValue
Gets the highest value that can be saved.
Declaration
public static DateTime MaxValue { get; }
Property Value
Type | Description |
---|---|
System.DateTime | The highest value that can be saved. |
Remarks
The highest value is currently 9999-12-31.
MinValue
Gets the lowest value that can be saved.
Declaration
public static DateTime MinValue { get; }
Property Value
Type | Description |
---|---|
System.DateTime | The lowest value that can be saved. |
Remarks
The lowest value is currently 1753-01-01.
Methods
ParseToUtc(String)
Converts the specified string representation of a date and time to its System.DateTime equivalent, with a System.DateTime.Kind value of DateTimeKind.Utc.
Declaration
public abstract DateTime ParseToUtc(string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | A string containing a date and time to convert. |
Returns
Type | Description |
---|---|
System.DateTime | An object that is equivalent to the date and time contained in |
Remarks
If a call to DateTime.Parse(string) with the same parameter would return a value with System.DateTime.Kind equal to DateTimeKind.Local, then the value is converted to local time; otherise, the result value is specified as UTC.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.FormatException |
|
ParseToUtc(String, IFormatProvider)
Converts the specified string representation of a date and time to its System.DateTime equivalent using the specified culture-specific format information, with a System.DateTime.Kind value of DateTimeKind.Utc.
Declaration
public abstract DateTime ParseToUtc(string value, IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | A string containing a date and time to convert. |
System.IFormatProvider | provider | An object that supplies culture-specific format information about |
Returns
Type | Description |
---|---|
System.DateTime | An object that is equivalent to the date and time contained in s as specified by |
Remarks
If a call to DateTime.Parse(string) with the same parameter would return a value with System.DateTime.Kind equal to DateTimeKind.Local, then the value is converted to local time; otherise, the result value is specified as UTC.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.FormatException |
|
ReadDatabaseValueAsLocal(Object)
Read an object returned from a database call to a Local DateTime value.
Declaration
public abstract DateTime? ReadDatabaseValueAsLocal(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | An object representing a DateTime returned from a database call. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | The converted value, or null if value is null or equal to DBNull.Value. |
ReadDatabaseValueAsUtc(Object)
Read an object returned from a database call to a UTC DateTime value.
Declaration
public abstract DateTime? ReadDatabaseValueAsUtc(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | An object representing a DateTime returned from a database call. |
Returns
Type | Description |
---|---|
System.Nullable<System.DateTime> | The converted value, or null if value is null or equal to DBNull.Value. |
ToLocalTime(DateTime, Boolean)
Converts value
to local time.
Declaration
public abstract DateTime ToLocalTime(DateTime value, bool convertUnspecified)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | value | The value to convert. |
System.Boolean | convertUnspecified | If true, values with DateTime.Kind set to DateTimeKind.Unspecified will be converted to local time (the same behavior as DateTime.ToLocalTime); if false, they will only have DateTime.Kind set to DateTimeKind.Local. |
Returns
Type | Description |
---|---|
System.DateTime | The possibly converted DateTime value. |
ToUniversalTime(DateTime, Boolean)
Converts value
to universal time.
Declaration
public abstract DateTime ToUniversalTime(DateTime value, bool convertUnspecified)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | value | The value to convert. |
System.Boolean | convertUnspecified | If true, values with DateTime.Kind set to DateTimeKind.Unspecified will be converted to universal time (the same behavior as DateTime.ToUniversalTime); if false, they will only have DateTime.Kind set to DateTimeKind.Utc. |
Returns
Type | Description |
---|---|
System.DateTime | The possibly converted DateTime value. |
TryParseToUtc(String, out DateTime)
Converts the specified string representation of a date and time to its System.DateTime equivalent, with a System.DateTime.Kind value of DateTimeKind.Utc; and returns a value that indicates whether the conversion succeeded.
Declaration
public abstract bool TryParseToUtc(string value, out DateTime result)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | A string containing a date and time to convert. |
System.DateTime | result | When this method returns, contains the System.DateTime value equivalent to the
date and time contained in |
Returns
Type | Description |
---|---|
System.Boolean | True if the |
Remarks
If a call to DateTime.Parse(string) with the same parameter would return a value with System.DateTime.Kind equal to DateTimeKind.Local, then the value is converted to local time; otherise, the result value is specified as UTC.
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The date is in Japanese Emperor Year (Wareki) format and the year is out of range. |